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

2 ビュー (過去 30 日間)
Luís Mira
Luís Mira 2021 年 4 月 3 日
回答済み: dpb 2021 年 4 月 4 日
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?

回答 (1 件)

dpb
dpb 2021 年 4 月 4 日
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.

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by