0

I have a source folder called "data". There are 29 subfolders in the source folder with each person's name on it. And, also there is two more subfolders. Under one of this subfolders corresponding to each name of the folder, there is a target file which is .csv format. For example, "data/001_Jake,..,029_Maria/001_Jake_subfolder/target_file.csv"

What I want to do is to move that all target files from the subfolders to new directory using loop.

Please help me out. Thank you.

I made for loop to move all files into new directory, but I have no idea of selecting .csv format files from subfolder.

sourcePath = '/Volumes/data' fileList = dir(sourcePath); 
fileList = fileList(~ismember({fileList.name},{'.','..','}));

dirFolder = "/Users/newDirectory/"

for i:length(fileList)
    movefile(fullfile(fileList(i).name, ))
beaker
  • 16,331
  • 3
  • 32
  • 49
  • You can get all csv files within nested subdirectories using `d = dir( '/Volumes/data/**/*.csv' );`. Does that get you most of the way there? I'd then loop over that structure and move `fullfile(d(i).folder,d(i).name)` to elsewhere – Wolfie Feb 21 '23 at 15:02

0 Answers0