Search for files in directory

214 visualizaciones (últimos 30 días)
Ana Royce
Ana Royce el 30 de Ag. de 2016
Respondida: Othmane ELMOUATAMID el 18 de Feb. de 2020
How do i search for certain file in all directory. Do i need to write loop statement? example filename : '*.xyx\test.txt' (* - refer directory c , d, f, g)
Provide me sample code. Advance Thanking

Respuestas (2)

Othmane ELMOUATAMID
Othmane ELMOUATAMID el 18 de Feb. de 2020
Just in case someone looks for the same problem :
I needed to list only .mat files that contains a specific string (here my variable "InputFileName") and begins with 'res_" :
dotMatFiles = struct2cell(dir(fullfile(path2MatRes,['res_*',InputFileName,'*.mat'])))';
This line of code get the list of all matlab files and stock the information into a cell array so I can loop through it later to get the full path of the files.
I hope this would help someone.

Azzi Abdelmalek
Azzi Abdelmalek el 30 de Ag. de 2016
Editada: Azzi Abdelmalek el 30 de Ag. de 2016
d='E:\' % your directory
f=dir(fullfile(d,'test.txt'))
  1 comentario
Ana Royce
Ana Royce el 30 de Ag. de 2016
i have few directories, don't want to hard code directory name

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by