필터 지우기
필터 지우기

Loop over files within a directory and all its sub-directories

조회 수: 3 (최근 30일)
Clifford Shelton
Clifford Shelton 2012년 12월 24일
댓글: Walter Roberson 2016년 9월 16일
Happy Holidays to everyone!
I have a folder: C:\data
and I wish to loop over all the files that are within the sub-folders that are named by dates in a MMDDYY fashion (example 122312, 122412, 122512...etc.)
The filenames of the files within each subfolder are all associated with the names of the strings in my array. (see sample code below)
After doing some research I'm not sure which function is best for my needs..nor do I know the proper syntax to utilize them without error. (I tried genpath, or numel with no success)
Any help is appreciated. Here is some example code:
%my FEEBLE attempt to begin to loop through the specified folder and all its sub-directories
for f = 1 : numel('files')
% The names of the files I will be analyzing
for Str = {'Red' 'Orange' 'Yellow' 'Green' 'Blue' 'Indigo' 'Violet'};
%I don't think this next line of code is right. But i'm trying to apply the names of each associated color with the name of the file to
%import
folder = 'c:\data';
fileToRead1 = [Str{1} '.xls'];
sheetName='Sheet1';
if exist(fileToRead1, 'file') == 0
% File does not exist
% Skip to bottom of loop and continue with the loop
continue;
end
% And then begin my calculations and functions here....
Thank you in advance! Ho Ho Ho!

답변 (2개)

Walter Roberson
Walter Roberson 2012년 12월 24일
  댓글 수: 2
Matthew
Matthew 2016년 9월 16일
this solution only looks for files within a single folder, not recursive on subfolders
Walter Roberson
Walter Roberson 2016년 9월 16일
Depth first or breadth first?
https://www.mathworks.com/matlabcentral/answers/32038-can-you-use-dir-to-list-files-in-subfolders

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


Jan
Jan 2016년 9월 16일

카테고리

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