How do I grab individual files from a directory path?

5 visualizaciones (últimos 30 días)
Haley Inniger
Haley Inniger el 4 de Mayo de 2015
Editada: Stephen23 el 4 de Mayo de 2015
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!

Respuesta aceptada

Stephen23
Stephen23 el 4 de Mayo de 2015
Editada: Stephen23 el 4 de Mayo de 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};

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by