Skip to content

vlt.file.manifestFileCount

 manifestFileCount Counts direct children within each directory from a manifest list.
    [folderList, childCounts] = manifestFileCount(fileList, isDir) processes
    a cell array of path strings and a corresponding logical vector
    indicating directories (output from the 'manifest' function).
    It returns a list of unique directories found and the count of *direct*
    children (files OR subfolders) within each directory. Empty directories
    listed in the input will be included with a count of 0.

    Input Arguments:
        fileList - Cell array of strings or string array, where each element
                   is a path (relative or absolute) as generated by the
                   'manifest' function. Must be sorted depth-first.
        isDir    - Logical vector, same size as fileList. isDir(i) must be
                   true if fileList(i) represents a directory, false otherwise.

    Output Arguments:
        folderList  - Cell array of strings containing the unique paths of
                      directories found in fileList, preserving their first
                      encountered order ('stable'). Includes empty directories.
        childCounts - Numerical column vector of the same size as folderList,
                      where childCounts(i) is the number of direct children
                      (files OR folders) listed in fileList for the directory
                      specified by folderList(i).

    Example:
        % Assume 'manifest' produced this:
        myFileList = { ...
            'DirA', ...             % isDir = true
            'DirA/File1.txt', ...   % isDir = false
            'DirA/SubDirA1', ...    % isDir = true
            'DirA/SubDirA1/File2.txt', ... % isDir = false
            'DirB', ...             % isDir = true (empty)
            'DirC/File3.txt' ...    % isDir = false (DirC not listed explicitly if empty)
        };
        myIsDir = [true; false; true; false; true; false]; % DirB is empty

        % If DirC was present in original scan but empty:
        % myFileList = { ..., 'DirB', 'DirC'}; myIsDir = [..., true, true];

        [folders, counts] = manifestFileCount(myFileList, myIsDir);
        % Expected Output (based on first myFileList):
        % folders = {'DirA'; 'DirA/SubDirA1'; 'DirB'}
        % counts = [2; 1; 0] % DirA has File1.txt & SubDirA1; SubDirA1 has File2.txt; DirB has 0

    See also: manifest, unique, startsWith, strsplit, cellfun, size