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"
...
0 个评论
采纳的回答
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 Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!