I have function in matlab (with a wrapper that actualy calls the function) that recursively finds all the .mat files in a given HDD on the computer. On every return it gives the files present in a specific folder, so since theres hundreds of folders on the drive (organized by date) there are hundreds of returns.
I'm trying to make one list (or matrix) of these files so that another script can use this list to do it's job.
The actual return is a list of structures (with fields containing file information). The returns are always one wide and a length depending on how many files are in the folder.
In short, I'd like to know how to take all the returns of a recursive function and put them into one list/matrix.
Any tips would be appreciated! Thank you
function direc = findDir(currentDir)
dirList = dir(currentDir);
if 2 == length(dirList)
direc = currentDir
files = dir([currentDir '*.mat'])
return
end
dirList = dirList(3:length(dirList));
fileListA = dir([currentDir '*.mat']);
if 0==isempty(fileListA)
direc = currentDir
files = dir([currentDir '*.mat'])
return
end
for i=1:length(dirList)
if dirList(i).isdir == 1
[currentDir dirList(i).name '\'];
findDir([currentDir dirList(i).name '\']);
end
end
end