Open and process files in subfolders
    11 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi everyone! i wrote a script to process a lot of files within a folder. Now, this folder is just a subfolder in the Input-folder and i would like to apply the script to all subfolders (all files within each subfolder). i've come so far:made a list of subfolders after selecting the input folder, but don't know how to get through the subfolders and files within them. can someone help? thanks
d=uigetdir('','Select Input-folder'); %select the input-folder that contains the subfolders
cd(d);
list = dir;
list = list([list.isdir]); 
list = list(~ismember({list.name},{'.' '..'}));
l=length(list);
for i=1:l
   ???? %open subfolder and apply script to files within it. 
end
0 comentarios
Respuestas (1)
  CS Researcher
      
 el 9 de Mayo de 2016
        
      Editada: CS Researcher
      
 el 9 de Mayo de 2016
  
      Why not do the same as you did above. Inside the for loop do this:
d=uigetdir('','Select Input-folder'); %select the input-folder that contains the subfolders
cd(d);
list = dir;
list = list([list.isdir]); 
list = list(~ismember({list.name},{'.' '..'}));
l=length(list);
for i=1:l
      oldfolder = cd(list(i).name);
      % Perform your operation on the files, e.g., if you are working with csv files
      files = dir('*.csv');
      numberOfFiles = length(files);
      for k = 1:numberOfFiles
          % You code goes here
      end
      cd(oldfolder); 
end
3 comentarios
Ver también
Categorías
				Más información sobre File Operations en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

