Can I use fullfile() to read two subfolders ?
Afficher commentaires plus anciens
Hi,
Im wondering is it possible to use fullfile to read two subfolder for further specific file extraction? For example, I have two subfolder, named 'Faces' and 'NonFaces', that are located in the main folder 'images'.
Main_Folder= 'D:\my_mfiles';
cd(Main_Folder)
subfolder=fullfile(Main_Folder, 'Faces','NonFaces') % Here went wrong
cd(subfolder)
I'd also tried this way, but it didnt work:
subfolder='Faces''NonFaces';
Or there is a better solution to read two subfolders?
Any suggestion is much appreciated!
2 commentaires
Of course you cannot set the current directory to two subfolders at the same time. There is one current directory only.
'Faces''NonFaces'
This creates the CHAR vector Faces'NonFaces with a single quote inside. Do not start to try guessing, what Matlab does, but read the example code in the documentation, e.g.:
doc fullfile
Stephen23
le 16 Nov 2018
Note that calling cd in your code is slow and makes debugging harder. It is recommended to simply pass the full filename to whatever function is reading/writing files. All MATLAB functions accept a relative/absolute filename, so this is what you should be doing.
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 16 Nov 2018
0 votes
fullfile(A,B,C) constructs [A filesep B filesep C]
fullfile is only about taking strings and mechanically putting them together as if they were parts of a qualified file name . It is a string manipulation routine .
You can never cd to two folders simultaneously . You can cd to subfolders but you can only be active in one folder at a time .
If you want to extract from multiple folders then fetch the names from one and then fetch the names from the other and put the two groups together .
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!