How do I grab individual files from a directory path?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am creating a GUI and I want the user to be able to select a file containing multiple .xml files, and then I need to be able to parse and work with the files within that directory separately. Right now, I am using uigetdir to get the file path but as that just returns a string, I do not know how to use that file path to grab the individual files. Any help will be appreciated, thanks!
0 commentaires
Réponse acceptée
Stephen23
le 4 Mai 2015
Modifié(e) : Stephen23
le 4 Mai 2015
You can use dir to get a list of all of the files in a directory. It also allows you to specify the a string to match particular files, you could use '*.xml' to select only files with that extension: see the documentation for more info and examples. Also note that you should use fullfile to generate the full filepath string:
pth = uigetdir(...);
fnm = fullfile(pth, '*.xml');
S = dir(fnm);
Where S is a structure containing lots of useful info. You can get a cell array of the filenames like this:
C = {S.name};
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!