I have a directory which has 3 folders. Each folder of these 3 folders has another number of folders. And in each folder of these folders there are a list of files which I want to run code on each of these file. So for example: its like this: MainFolder has SubFolder1, SubFolder2. SubFolder1 has SubSubFolder1,SubSubFolder2,SubSubFolder3. SubFolder2 has SubSubFolder1,SubSubFolder2. Each of the SunSubFolders has a number of files. I want a script that I give it the MainFolder Path and it goes through each subfolder and subsubfolder and do operations on the files in this subsubfolder and saves the workspace by the name of this subsubfolder. So in the above example, after doing some work on the files in the SubSubFolder1 the resulted workspace will be saved in a location with the name SubSubFolder1.mat.
Please I'm asking if anyone could assist me as this is fairly urgent for me. Many Thanks for your kind assistance and consideration.
Update:
I've done it but another problem rose up in which when I access the files in the SubSubFolders and try to make operation it says "The file '[00000000].pgm' could not be opened because: No such file or directory". How to solve this issue?
this is my code:
D = rdir('Hussein/*/*'); %// List of all sub-directories
for k = 1:length(D)
currpath = D(k).name; %// Name of current directory
[pathstr, name, ext] = fileparts(currpath);
%// Operate on all .txt files in currpath
l = dir(fullfile(currpath, '*.pgm')); %// Listing of all relevant files
filenames={l.name}';
nfiles=length(filenames)
%images=zeros(240, 320, 1000);
idx=1;
strtidx=1;
endidx=nfiles;
step=1;
waitbar(0);
for i=strtidx:step:endidx
fn=fullfile('', filenames{i});
tmp=padarray(ut_pgmread(fn), 1, 'post');
%figure(1); imagesc(tmp); colormap(jet(4096)); colorbar;
images(:, :, idx)=tmp; idx=idx+1;
waitbar(i/nfiles);
end
close(findall(0,'Tag','TMWWaitbar'));
name='/Volumes/Untitled/work/'+name;
save (name, '-v7.3');
%for m = 1:length(F)
% currfile = F(m).name; %// Name of current file
%// Do something with currfile...
%end
%// Write output (if any) in currpath...
end;