Search for a specific file in a parallel folder in Matlab
3 views (last 30 days)
Show older comments
Oliver Klein
on 15 Aug 2023
Commented: Oliver Klein
on 15 Aug 2023
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 Comments
Accepted Answer
Florian Bidaud
on 15 Aug 2023
Edited: Florian Bidaud
on 15 Aug 2023
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
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!