Where can I find the directory for things like '*.xls', '%04df' or something?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Duc Tran
am 22 Dez. 2021
Kommentiert: Duc Tran
am 22 Dez. 2021
Hello,
I am self teaching myself MATLAB so my apology if this is a very basic question. I want to use the function 'dir' to go into a folder and make a struct with only those files ending in '.xls' or '.xlsx'. Below is what I currently have and I would like to know how I can make it to also list '.xlsx' file in the same struct.
In addition, I would like to know where I can go to understand the nomenclature? of words like '%04df' and others.
xlsFiles = dir(fullfile(folderName, '*.xls'))
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 22 Dez. 2021
xlsFiles = dir(fullfile(folderName, '*.xls*'))
should get .xls and .xlxs files. But it would also get .xlsm and any other file extension that started with .xls .
To be specific about xlsx and xls and you want them in the same structure, there are two ways:
xlsFiles = [dir(fullfile(folderName, '*.xls'));
dir(fullfile(folderName, '*.xlsx'))];
OR
xlsFiles = dir(fullfile(folderName, '*.xls*'));
[~, ~, ext] = fileparts({xlsFiles.name});
mask = ismember(ext, {'.xls', '.xlsx'});
xlsFiles = xlsFiles(mask);
Weitere Antworten (1)
Rik
am 22 Dez. 2021
I would personally go the easy route and merge the two separate structs, but you could try this:
xlsFiles = dir(fullfile(folderName, '*.xls*'));
As for '%04d', that look like a format specification. You should read the documentation for fprintf or sprintf (although num2str supports this as well).
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!