Summary
This function aims to simplify the process of recursively listing the contents of a folder tree by the use of optional name-value pairs that provide fine grained control over the items to be returned.
The main difference between this function and the many alternatives that exist on FEX is a simple and intuitive set of options to filter the search results.
Examples
1) List all files and folders under the current directory
combinedListing = recursiveDir(pwd());
2) List all MATLAB (.m) files under the current directory
combinedListing = recursiveDir(pwd(), "FileType", ".m");
3) List all folders under the current directory with depth limit of 2
combinedListing = recursiveDir(pwd(), "Type", "folder", "RecursionDepth", 2);
4) List all files and folders under multiple root paths
rootPaths = ["path1", "path2", "path3"];
combinedListing = recursiveDir(rootPaths);
Options
The following options are available for customizing the result of listing the contents of a folder tree:
IgnoreList - List of words/substrings to ignore during
listing. Default is an empty string array.
Expression - Regular expression to filter files and folders.
Default is an empty string.
Type - Type of items to list: 'file', 'folder', or
'any'. Default is 'any'.
FileType - File extension for filtering specific files.
Default is an empty string.
RecursionDepth - Maximum recursion depth. Default is inf.
IsCumulative - Flag to indicate whether to accumulate files
and/or folders as the function goes deeper into
the directory tree. Default is true. If false,
only files and folders from the depth specified
in RecursionDepth will be returned.
OutputType - Type of output: 'FileAttributes', 'FilePath' or
'RelativeFilePath'. Default is 'FileAttributes'
(struct array as returned by the builtin dir
function).
IncludeHiddenFiles - Flag to include hidden files and folders.
Default is false (Unix only).
引用格式
Eivind Hennestad (2024). Recursively list files and folders (https://www.mathworks.com/matlabcentral/fileexchange/160058-recursively-list-files-and-folders), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2023b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!