by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - File handling
Introduced first in SolidGeometry 5.3, Creation date: 2023-03-14, Last change: 2025-09-15
See Also:
ddl=dir2cell(dd)
dd: | result of a dir command |
ddl: | cell list of file names |
dir2cell(dir(desktopdir))
This function, dir2cell, is designed to convert the output of a MATLAB dir command into a cell array of file names. It is part of the SolidGeometry library, specifically for file handling tasks.
dir command in MATLAB. It is a structure array where each element represents a file or directory, containing fields such as name, folder, and other metadata.folder field is present in the input structure, or just the file names if it is not.dd using numel(dd).ddl with the same number of elements as dd, each initialized to an empty cell.dd using a for loop.folder field exists using isfield(dd, 'folder').folder field exists, concatenate the folder and name fields with a file separator filesep and store the result in the corresponding cell of ddl.folder field does not exist, store only the name field in the corresponding cell of ddl.To use this function, you can call it with the result of a dir command, such as:
ddl = dir2cell(dir(desktopdir));
This will convert the directory listing of desktopdir into a cell array of file paths or names.