I am using the following code to read all files from a folder:
Files=dir('*');
for k=1:length(Files)
FileNames=Files(k).name;
end
However I want to read the files which names begin with "word" not just all files in folder. How can I perform such task?

 채택된 답변

Image Analyst
Image Analyst 2014년 7월 1일

4 개 추천

Files=dir('word*.*');

댓글 수: 7

Reema Alhassan
Reema Alhassan 2018년 5월 24일
hey but here we didn't specify the folder name is that ok?
Yes, it will use files in the current folder. If you want them in a particular folder, you can do
folder = pwd; % or 'D:\my Images\Reema' or wherever...
filePattern = fullfile(folder, 'word*.*');
fileList = dir(filePattern);
Thank you
it was very helpful
sania urooj
sania urooj 2021년 2월 13일
hey! I want to read files (mat) also, the name of the folder (label) . What to do?
Image Analyst
Image Analyst 2021년 2월 13일
@sania urooj, I'm not sure what names you have and what you want. Why can't you just change the filePattern wildcard to be what you want???
Ihaveaquest
Ihaveaquest 2022년 8월 16일
what if there are multiple files with similar name but you only want the most current created ??
@Ihaveaquest, to find the newest file, do this:
fileList = dir('t*.m')
fileDates = [fileList.datenum]
% Find newest file
[maxDate, index] = max(fileDates)
fprintf('The newest file is:\nName: %s\nDate: %s\n', ...
fileList(index).name, fileList(index).date)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2014년 7월 1일

댓글:

2022년 8월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by