list the subfolders in a folder - Matlab (only subfolders, not files)

后端 未结 4 1863
心在旅途
心在旅途 2020-12-25 12:13

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

nameFolds = dir(pathFolder), 

I get . and ..

4条回答
  •  青春惊慌失措
    2020-12-25 12:36

    The following code snippet just returns the name of sub-folders.

    % `rootDir` is given
    dirs = dir(rootDir);
    % remove `.` and `..`
    dirs(1:2) = [];
    % select just directories not files
    dirs = dirs([obj.dirs.isdir]);
    % select name of directories
    dirs = {dirs.name};
    

提交回复
热议问题