How to pick files from sub-folder
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Aishwarya Sanaka
il 25 Feb 2021
Commentato: Bob Thompson
il 9 Lug 2022
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.
0 Commenti
Risposta accettata
Bob Thompson
il 25 Feb 2021
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.
end
5 Commenti
Monalisa Chikezie
il 9 Lug 2022
Dot indexing is not supported for variables of this type.
For me, my main folder has 70 subfolders. Each of the sub folders have 4 files.
Bob Thompson
il 9 Lug 2022
Please share more of your code. From what I posted here, the error indicates that somehow 'folders' is not a structure class, but without knowing more about where the error is occurring in your work, I can't say if that's actually the problem.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!