I have a folder splitted.frames, It contains subdirectories like "21434343", "125521","25778" and so on. (random numbers as sub-directory name) Each subdirectory have thousand of images.

I need to make, my code generic that it read all subdirectories one by one and I have written a piece of code that work really fine for single directory and process all files in it. How should a program select sub-directory one by one. please help me out.

Réponses (1)

master_folder = 'splitted.frames';
master_dinfo = dir(master_folder);
master_dinfo = master_dinfo([master_dinfo.isdir]);
now master_dinfo contains information only for subdirectories and you can loop
for K = 1 : length(master_dinfo)
this_folder_name = master_dinfo(K).name;
if this_folder_name(1) == '.'; continue; end %skip '.' and '..'
subdir_name = fullfile(master_folder, this_folder_name);
subdir_dinfo = dir(subdir_name);
subdir_dinfo([subdir_dinfo.isdir]) = []; %remove directories
for L = 1 : length(subdir_dinfo)
this_filename = fullfile( subdir_name, subdir_dinfo(L).name );
... now process this_filename
end
end

Cette question est clôturée.

Tags

Aucun tag saisi pour le moment.

Question posée :

le 2 Août 2015

Clôturé :

le 20 Août 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by