Required :- A simple piece of code to list the files in a dir and return the select file name as a string.
Mostrar comentarios más antiguos
Hi All
As stated in my question I am after what I imaging is a commonly required and hopefully simple piece of code to provide a drop down list of files in a directory. The selected file name would then be returned so the contents can be processed.
Would be much obliged if anyone can point me to an example.
Many thanks
Tom
1 comentario
Jan
el 30 de Ag. de 2012
Do you need a drop-down list for any reasons, or does UIGETFILE matchs your needs already?
Respuestas (3)
Sean de Wolski
el 30 de Ag. de 2012
doc uigetfile
1 comentario
Jan
el 30 de Ag. de 2012
This is exactly the dialog users are expecting.
Matt Tearle
el 30 de Ag. de 2012
As Sean suggests, uigetfile provides a standard file selection dialog box. Otherwise, you can also use dir or ls to get a file listing of a directory.
For example:
fls = cellstr(ls('*.m'))
k = menu('Pick your file',fls)
filetodostuffwith = fls{k}
1 comentario
Sean de Wolski
el 30 de Ag. de 2012
Or listdlg:
listdlg('ListString',fls)
If is really must be a drop-down list - but I'd prefer Sean's suggestion:
DirList = dir(Folder);
FileList = {DirList.name};
FileList(strncmpi(FileList, '.', 1)) = []; % neither . nor ..
uicontrol('Style', 'popupmenu', 'String', FileList, ...
'Callback', @mySelect);
function mySelect(ObjH, EventData)
Value = get(ObjH, 'Value');
String = get(ObjH, 'String');
disp(String{Value});
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!