reading files of folders with specific name styles
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am attempting to look for the codes required to open specific folders withing a particular folder, as shown below.
Within this directory, I wish to read the files of the folders with only Att in their names. So, in this case, only files in folders Att10, Att20, Att30, and Att40 will be read. Each folder contains 100 files which will be then used for image processing.
I am attempting to use two for loops:
as in,
First for loop to open each folder,
the second for loop to process each image in each folder.
Can one please help with this?
Kind regards,
Nilesh
댓글 수: 0
답변 (2개)
MarKf
2022년 12월 1일
Adapt, test, correct, or simplify following code:
Dir_with_Att = 'C:\Users\etc\put_your_directory_path_here\maybe_use_fullfile_here_too';
attdirs = dir(fullfile(Dir_with_Att,'Att*'));
attdirnames = {attdirs(:).name}; % just the dir names
attpaths = (fullfile(Dir_with_Att,attdirnames)); % full paths
for idr = 1:numel(attdirnames)
apath = attpaths{idr};
afiles = dir(fullfile(apath,'*.png')); % or .jpg etc
for idf = 1:numel(afiles)
path2img = fullfile(apath, afiles(idf).name);
%do stuff to img
end
end
댓글 수: 0
Stephen23
2022년 12월 1일
P = 'absolute or relative path to where the folders are';
S = dir(fullfile(P,'Att*','*.*')); % specify the file extensions
for k = 1:numel(S)
F = fullfile(S(k.folder,S(k).name));
... do whatever with filename F
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Search Path에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!