Search for a specific file in a parallel folder in Matlab

8 ビュー (過去 30 日間)
Oliver Klein
Oliver Klein 2023 年 8 月 15 日
コメント済み: Oliver Klein 2023 年 8 月 15 日
Hello everyone,
my desired function is to automate my scripts which are placed in different parallel folders (all folders in one parent folder). I have one folder where all the data files should be stored (6_Data). In this folder there are a lot of folders with different data files. The names of the data files are always structured like date_time_"customname". The customname is always known in the different scripts but the date and the time are not.
So is there a way to search in the 6_Data folder for the folder with the specific "customname"?
Here is the structure of parent folder (schematic)
Parent folder
1_Scriptfolder
- Script1.m
2_Scriptfolder
- Script2.m
3_Scriptfolder
4_Scriptfolder
5_Scriptfolder
6_Data
date_time_"customname1"
Datafile1.mat
Datafile2.mat
date_time_"customname2"
...

採用された回答

Florian Bidaud
Florian Bidaud 2023 年 8 月 15 日
編集済み: Florian Bidaud 2023 年 8 月 15 日
If the customnames are unique, you can use:
your_path = 'C:\...\6_Data';
custoname = 'customname1';
folders = dir(your_path);
for i = 1:length(folders)
if contains(folders(i).name,customname)
folder_path = fullfile(your_path,folders(i).name);
break
end
end

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by