I have code that executes a for loop through a folder and all of its subdirectories. My questions is how do I write the code in order to :
A.) check if a file is present within the folder in the for loop, and then
B.) skip that folder containing the file IF the file is present.
Here is the code i have been fumbling with so far:
mainFolder = 'c:\data';subdirs = dir(mainFolder);%This filters out all the items in the main folder that are not directories
subdirs(~[subdirs.isdir]) = [];%And this filters out the parent and current directory '.' and '..'
tf = ismember( {subdirs.name}, {'.', '..'});subdirs(tf) = [];numberOfFolders = length(subdirs);% %Here i am creating the variables to iterate over the date folders
% dates = fieldnames(subdirs);
% for loopIndex = 1:numel(dates)
% stuff = subdirs.(dates{loopIndex})
% end
% Here I begin the for loop. My aim is to tell the program to skip all %the folders that contain the file "Present.txt"
for K = 1: numberOfFoldersthissubdir = subdirs(K).name;subdirpath = [mainFolder '\' thissubdir];%This is WRONG WRONG WRONG... help please?
if exist('Present.txt') == 1 continue end
Thanks for all the help!
Best Answer