Recursively list files and folders

버전 1.0.3 (3.39 KB) 작성자: Eivind Hennestad
Recursively lists files and folders under the specified root path using options to filter results
다운로드 수: 40
업데이트 날짜: 2024/7/3

라이선스 보기

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 (2025). Recursively list files and folders (https://kr.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!
버전 게시됨 릴리스 정보
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