Search for files in directory

178 次查看(过去 30 天)
Ana Royce
Ana Royce 2016-8-30
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

回答(2 个)

Othmane ELMOUATAMID
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 2016-8-30
编辑:Azzi Abdelmalek 2016-8-30
d='E:\' % your directory
f=dir(fullfile(d,'test.txt'))
  1 个评论
Ana Royce
Ana Royce 2016-8-30
i have few directories, don't want to hard code directory name

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by