clc;
workspace;
format longg;
format compact;
start_path = fullfile(matlabroot, '\toolbox\images\imdemos');
topLevelFolder = uigetdir(start_path);
if topLevelFolder == 0
return;
end
allSubFolders = genpath(topLevelFolder);
remain = allSubFolders;
listOfFolderNames = {};
while true
[singleSubFolder, remain] = strtok(remain, ';');
if isempty(singleSubFolder)
break;
end
listOfFolderNames = [listOfFolderNames singleSubFolder];
end
numberOfFolders = length(listOfFolderNames)
for k = 1 : numberOfFolders
thisFolder = listOfFolderNames{k};
fprintf('Processing folder %s\n', thisFolder);
filePattern = sprintf('%s/*.png', thisFolder);
baseFileNames = dir(filePattern);
filePattern = sprintf('%s/*.tif', thisFolder);
baseFileNames = [baseFileNames; dir(filePattern)];
filePattern = sprintf('%s/*.jpg', thisFolder);
baseFileNames = [baseFileNames; dir(filePattern)];
numberOfImageFiles = length(baseFileNames);
if numberOfImageFiles >= 1
for f = 1 : numberOfImageFiles
fullFileName = fullfile(thisFolder, baseFileNames(f).name);
fprintf(' Processing image file %s\n', fullFileName);
end
else
fprintf(' Folder %s has no image files in it.\n', thisFolder);
end
end
Best Answer