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

2 views (last 30 days)
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?

Answers (1)

dpb
dpb on 4 Apr 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.

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!