How to make a script so I can choose a file from folders

2 vues (au cours des 30 derniers jours)
Luís Mira
Luís Mira le 3 Avr 2021
Réponse apportée : dpb le 4 Avr 2021
I'm in my last year of graduation and I'm doing a research project about space weather. To summarize, I've some data distributed by several folders. There are many folders inside each one and I have to build a script to pick each folder content. How should I do it?

Réponses (1)

dpb
dpb le 4 Avr 2021
While it's only documented by a very terse example, the builtin dir function will recurse directories if the search pattern contains "**/" preceding the pattern given for the file match itself.
That is,
d=dir('**/*.xlsx');
will return all Excel files of the explicit .xlsx type from the current directory and all subdirectories below. Giving a specific top level directory of the data storage location in combination with the wildcard will give you the full structure below that location.
You'll also want to explore fullfile and fileparts in processing the results and in preparing the input filename strings.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by