Search for a specific file in a parallel folder in Matlab

3 visualizaciones (últimos 30 días)
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"
...

Respuesta aceptada

Florian Bidaud
Florian Bidaud el 15 de Ag. de 2023
Editada: Florian Bidaud el 15 de Ag. de 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

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by