Search for a specific file in a parallel folder in Matlab

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by