How do I grab individual files from a directory path?

10 views (last 30 days)
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!

Accepted Answer

Stephen23
Stephen23 on 4 May 2015
Edited: Stephen23 on 4 May 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};

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!