Search for files in directory

조회 수: 218 (최근 30일)
Ana Royce
Ana Royce 2016년 8월 30일
답변: Othmane ELMOUATAMID 2020년 2월 18일
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
Othmane ELMOUATAMID 2020년 2월 18일
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에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by