How to pick files from sub-folder
조회 수: 18(최근 30일)
I have two sub-folders with images and require to perform operations using them. When i am running the code with sub-folder in the current folder window its being executed but i need to extract them from the main folder and run them. Also the ouput is a text file, which needs to be present in respective sub-folders instead of the current folder window. Please help me with these issues. Thank you in advance.
Bob Thompson 2021년 2월 25일
I recommend using dir to capture all the contents of your parent folder within a variable. Then you can use the contents of that variable to specify which child folder you want to work in.
folders = dir('parent folder path'); % Captures all contents of parent folder
folders = folders([folders(:).isdir]==1); % Filter to just folders
folders = folders(3:end); % Remove unnecessary '.' and '..' directories
for i = 1:length(folders)
path = [folders(i).folder,'\',folders(i).name];
% do work with path variable directing to each child folder.