How do I grab individual files from a directory path?

5 次查看(过去 30 天)
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!

采纳的回答

Stephen23
Stephen23 2015-5-4
编辑:Stephen23 2015-5-4
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 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by