dir2cell

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

folder files as cell list



See Also:

Example Illustration

 missing image of dir2cell(dd)

Syntax

ddl=dir2cell(dd)

Input Parameter

dd: result of a dir command

Output Parameter

ddl: cell list of file names

Examples


dir2cell(dir(desktopdir))




Copyright 2023-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

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.

Input Parameters

Output Results

Algorithm Steps

  1. Determine the number of elements in the input structure array dd using numel(dd).
  2. Initialize a cell array ddl with the same number of elements as dd, each initialized to an empty cell.
  3. Iterate over each element of the input structure array dd using a for loop.
  4. For each element, check if the folder field exists using isfield(dd, 'folder').
  5. If the folder field exists, concatenate the folder and name fields with a file separator filesep and store the result in the corresponding cell of ddl.
  6. If the folder field does not exist, store only the name field in the corresponding cell of ddl.

Example Usage

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.

Algorithm explaination created using ChatGPT on 2025-08-18 22:17. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21