Skip to content

vlt.file.manifest

 manifest Generates a hierarchical list of files and directories.
    [fileList, isDir] = manifest(folderPath) returns a cell array of
    relative paths and a corresponding logical vector indicating if each
    entry is a directory. Paths are relative to the PARENT directory of
    folderPath.

    [fileList, isDir] = manifest(folderPath, ReturnFullPath=true) returns
    full, absolute paths and the corresponding logical isDir vector.

    The list is sorted hierarchically in a depth-first manner, with
    siblings at any level sorted alphabetically.

    Input Arguments:
        folderPath - Path to the directory to scan (string or char vector).
                     Must be an existing folder.

    Optional Name-Value Arguments:
        ReturnFullPath - Scalar logical/numeric or empty (default: false).
                         If true or 1, returns full absolute paths.
                         If false, 0, or [] (default), returns paths
                         relative to the parent of folderPath.

    Output Arguments:
        fileList   - Cell array of strings, containing relative or full paths.
        isDir      - Logical column vector, same size as fileList. isDir(i)
                     is true if fileList(i) represents a directory, false otherwise.

    Example:
        % Create a temporary directory structure for testing
        baseTestDir = fullfile(pwd, 'test_manifest_base');
        targetDir = fullfile(baseTestDir, 'target_folder');
        if exist(baseTestDir, 'dir'), rmdir(baseTestDir, 's'); end
        mkdir(baseTestDir); mkdir(targetDir); mkdir(fullfile(targetDir, 'subdir_a'));
        fclose(fopen(fullfile(targetDir, 'file_f.txt'), 'w'));
        fclose(fopen(fullfile(targetDir, 'subdir_a', 'file_b.txt'), 'w'));

        % Generate relative paths and isDir flags
        [relList, isDirFlags] = manifest(targetDir);
        disp('Relative Manifest & isDir:');
        disp([relList num2cell(isDirFlags)]);
        % Expected: 'target_folder/file_f.txt' 0; 'target_folder/subdir_a' 1; 'target_folder/subdir_a/file_b.txt' 0

        % Generate full paths and isDir flags
        [fullList, isDirFlagsFull] = manifest(targetDir, ReturnFullPath=true);
        disp('Full Path Manifest & isDir:');
        disp([fullList num2cell(isDirFlagsFull)]);

        % Clean up
        rmdir(baseTestDir, 's');

    See also: dir, fullfile, fileparts, mustBeFolder, arguments, sort, cellfun, arrayfun, startsWith, strrep, char