Is there a way to tell uigetfile to start browsing in a folder other than the current one?
53 views (last 30 days)
Show older comments
Sometimes I run uigetfile multiple times and the user will typically want to read in files from the same directory/folder each time. I'm looking for a way to tell uigetfile to resume browsing from the last folder visited in the previous call to uigetfile. I can easily obtain the path name of the last folder visited, but can't see how to tell uigetfile to resume from there, other than to CD to the folder, which is awkward for various reasons, and not the solution I prefer.
I'd like to be able to do similar things with uiputfile, etc... Any suggestions?
0 Comments
Accepted Answer
Azzi Abdelmalek
on 25 Jul 2013
Edited: Azzi Abdelmalek
on 25 Jul 2013
Edit
uigetfile('*.m','select the m file','E:/matlab')
3 Comments
David Borrego
on 2 Nov 2021
Hello,
Do you know how to make it work for a folder out of the .m folder domain?
More Answers (1)
Jan
on 25 Jul 2013
CD is not really awkward in my opinion:
persistent lastFolder
if isempty(lastFolder)
lastFolder = cd;
end
bakCD = cd;
cd(lastFolder);
[file, folder] = uigetfile('*.*', 'Choose a file');
cd(bakCD);
if ischar(folder)
lastFolder = folder;
end
...
This opens automatically the last used folder, which is an intuitive behavior. Of course this would work with the method suggested by Azzi also.
See Also
Categories
Find more on Dialog Boxes 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!