how to save the dir output?

13 Ansichten (letzte 30 Tage)
Rehab Ali
Rehab Ali am 11 Nov. 2016
Beantwortet: Image Analyst am 11 Nov. 2016
Hello everyone,
I need to list all files in a folder, so I used dir /D/myfolder.
The problem is that I need to save this list in file or even variable in matlab
anyone can help me?

Antworten (2)

Image Analyst
Image Analyst am 11 Nov. 2016
Try this well commented snippet:
% Get a list of all files in the folder with the desired file name pattern.
myFolder = pwd; % Wherever you want.
filePattern = fullfile(myFolder, '*.*'); % Change to whatever pattern you need, for example *.m or whatever...
theFiles = dir(filePattern); % Ask operating system for the directory information.
% Extract only the filename part of the structure into its own variable.
allFileNames = {theFiles.name};
% Optional: Display the list in the command window just to double check what it is:
celldisp(allFileNames);

James Tursa
James Tursa am 11 Nov. 2016
dir_list = dir('/D/myfolder');

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by