列出一个文件夹中的子文件夹 - Matlab(只有子文件夹,而不是文件) [英] list the subfolders in a folder - Matlab (only subfolders, not files)

查看:307
本文介绍了列出一个文件夹中的子文件夹 - Matlab(只有子文件夹,而不是文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Matlab列出文件夹中的子文件夹。如果我使用

  nameFolds = dir(pathFolder),

我得到 .. +子文件夹名称。然后我必须运行 nameFolds(1)= [] 两次。有没有更好的方法来获取使用Matlab的subFolder名称?谢谢。

解决方案

使用 isdir dir 输出到单独的子目录和文件:

  d = dir(pathFolder); 
isub = [d(:)。isdir]; %#返回逻辑向量
nameFolds = {d(isub).name}';

然后您可以删除 ..

  nameFolds(ismember(nameFolds,{'。' 。'}))= []; 

你不应该做 nameFolds(1:2)= [] ,因为根目录下的 dir 输出不包含这些点文件夹。至少在Windows上。


I need to list the subfolders inside a folder using Matlab. If I use

nameFolds = dir(pathFolder), 

I get . and .. + the subfolder names. I then have to run nameFolds(1) = [] twice. Is there a better way to get the subFolder names using Matlab? Thanks.

解决方案

Use isdir field of dir output to separate subdirectories and files:

d = dir(pathFolder);
isub = [d(:).isdir]; %# returns logical vector
nameFolds = {d(isub).name}';

You can then remove . and ..

nameFolds(ismember(nameFolds,{'.','..'})) = [];

You shouldn't do nameFolds(1:2) = [], since dir output from root directory does not contain those dot-folders. At least on Windows.

这篇关于列出一个文件夹中的子文件夹 - Matlab(只有子文件夹,而不是文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆