Recursively list files and folders
Version 1.0.3 (3,39 KB) von
Eivind Hennestad
Recursively lists files and folders under the specified root path using options to filter results
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).
Zitieren als
Eivind Hennestad (2025). Recursively list files and folders (https://de.mathworks.com/matlabcentral/fileexchange/160058-recursively-list-files-and-folders), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Erstellt mit
R2023b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
| Version | Veröffentlicht | Versionshinweise | |
|---|---|---|---|
| 1.0.3 | Fix: There was a bug leading to comparison of logical vectors of different lengths if value of Expression was non-empty and items matched patterns in IgnoreList |
||
| 1.0.2 | Added "RelativeFilePath" as an alternative for "OutputType |
||
| 1.0.1 | Update description |
||
| 1.0.0 |
