1 function fileList = getAllFiles(dirName)
2 dirData = dir(dirName); %
# Get the data for the current directory 3 dirIndex = [dirData.isdir]; %# Find the index
for directories
4 fileList = {dirData(~dirIndex).name}
'; %'# Get a list of the files
6 fileList = cellfun(@(x) fullfile(dirName,x),... %
# Prepend path to files 7 fileList,
'UniformOutput',
false);
9 subDirs = {dirData(dirIndex).name}; %# Get a list of the subdirectories
10 validIndex = ~ismember(subDirs,{
'.',
'..'}); %# Find index of subdirectories
11 %# that are not
'.' or
'..' 12 for iDir = find(validIndex) %# Loop over valid subdirectories
13 nextDir = fullfile(dirName,subDirs{iDir}); %# Get the subdirectory path
14 fileList = [fileList; getAllFiles(nextDir)]; %# Recursively call getAllFiles