File Exchange

image thumbnail

uipickfiles: uigetfile on steroids

version (14.7 KB) by Douglas Schwarz
Many-featured, platform independent file and directory picker.


Updated 15 Jun 2020

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This is a GUI application that allows multiple files or directories to be selected and allows you to manage the list (remove files, reorder, etc.) before returning. It has basic filtering as well as regular expression filtering and navigation of the file system is easy. The output is configurable (cell, struct or char arrays). It is written entirely in M and so is platform independent.

Cite As

Douglas Schwarz (2021). uipickfiles: uigetfile on steroids (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (146)

Patrick Mirek

A note for anyone inputting variables for the property values (i.e., setting FilterSpec to the path of the last opened file), make sure that the value is a char, not a string. I almost lost it trying to figure this one out...

Elmar Gool

Hi Douglas, Thanks. I've finally found the problem indeed; the preference '('uipickfiles','figure_position')' was altered somehow to outside of my screen (not sure why). i reverted it back to a normal position via setpref('uipickfiles','figure_position',[100 100 1000 800]) and now the window is finally showing normally again.
Cheers, and love the function btw.

Douglas Schwarz

Elmar, I don't know what could be wrong. Do you have any other figures open? Try "close all force" before running uipickfiles. Do you have the default uicontrol units set to something other than pixels? (get(groot,'defaultuicontrolunits')). Otherwise, try single stepping through the function with the debugger. Each time a uicontrol is created, see if you can determine where it is. Good luck! -Doug

Elmar Gool

I am having a problem with the function on Matlab 2018b -> the function gets stuck while opening the window of the gui. The window is there, but it is completely empty and I am unable to do anything other than to close the window (giving empty results back). I managed to abort (ctrl+C) the code, which shows its stuck on line 644: uiwait(fig); I have the feeling the window content is somehow simply not showing up.

Daniel Dickinson

This is just spectacular.

Ganesh Naik

deng junmin

Chang hsiung


Thank you!

Douglas Schwarz

Hi William, first, thanks a lot for the tip on getting the folder image to show up. I don't know which is the first version of MATLAB where that is required, but certainly R2020a needs it. I actually haven't used uipickfiles since I updated to R2020a so thanks for noticing the problem and fixing it. I will include it in an update. The other problem is probably because I don't think I ever uploaded a fixed version of uipickfiles, but just let people fix it themselves. It's been a while since I gave this function any attention!

William Thielicke

Sorry for the spamming, but why is Mathworks too lazy to implement a proper comments & ratings section...? Boy....
If I use the hint that Douglas gave a while ago, then it works again:
dir_picks = repmat(dir(char(127)),0,1);

William Thielicke

If you want to have the little folder icon displayed next to folder in newer Matlab releases, you need to modify the line
fsdata.pre = sprintf('<HTML><img src="%s">&nbsp;',icon_url);
fsdata.pre = sprintf('<HTML><img width=12 height=10 src="%s">&nbsp;',icon_url);


Shambavi Ganesh

Steven Beiter

This has been a life saver on time. I have even used this as a basis for completely different GUIs as I am new to Matlab and making my own from scratch would be impossible right now. I do have one question though. Is there a way I could get the GUI to ignore files smaller than a certain size. Sort of like how it ignores duplicates?

Mehmet Agaoglu


Aaron Wells

Just fantastic!

Travis Hernandez

Lucas Machado

Joaquin REYES

Sébastien Herbert

Lionel Juillen AF

Michael Rowlands

Great tool ! Simple, elegant with a lot of features. I like the rtclick to get the history of recently used directories. I also like the optional regexp search.

Mike Denny

Not sure if I can even calculate the amount of time this saves me! I can also confirm the one line of code Douglas mentions below fixes the 'Struct' output when using R2015(b).


Katherine Farnsworth


One of the best! A very neat work!

Davide Miani


Very useful tool! Excellent execution and functionality, kudos!

One little thing - It took me a while to find the feature that lets you open a list of recent folders to flash-nav to. I think it would be more intuitive to have that as a drop-down box from the current folder box or something of that sort. Maybe this is not straightforward using matlab's GUIDE.

At any rate, a much needed resource, thanks!

Rebecca Burrell


fast, accurate, and reliable. the best of its kind

Douglas Schwarz

Katharina, please check that you have made this change to the copy of the m-file on your PC:

Change the line (on or near line 186)

dir_picks = dir(' '); % Create empty directory structure.

to be

dir_picks = repmat(dir(char(127)),0,1); % Create empty directory structure.

If that doesn't fix the problem, email me and I will investigate further.


Hi Doug, thanks for this fantastic tool! I use it all the time. Just wanted to mention that the problem which occurs on MATLAB 2015a & b is not fixed for me. If struct is used as output I get the folders I selected + the names of all other folders in that directory. (This does not happen if cell is selected as output and also does not happen on my Mac. ).

Alexis Krueger

Fantastic! Exactly what I needed for a multiple folder selection tool, so helpful.

E. Cheynet

This is probably one of the File Exchange submission I like most :)

Douglas Schwarz

Lex, you can access folder on a server, but you have to type in the server name, e.g., "\\server\folder". It's true that it doesn't provide a list of possible servers on the local network.


Works like a dream except it can only access folders on my computer. If you want to find a file on a folder on a server, it is unable to direct you to the network.

I am using Matlab 2013


Andreas Martin

Vadim Frolov

Douglas Schwarz


1. This function is designed to work across platforms and is not exclusively a Windows function.

2. You can do what you want using the regular expression filter. Simply type '\.csv$|\.txt$' in the Regular Expression Filter box. This exact application is given as an example in the documentation.


Reto Zingg

Hi Ravi, very nice function. A handy addition would be to allow multiple filters in the 'Type' parameter. Standard Windows behavior is that I can for example type '*.csv;*.txt' and all files with these two endings will be shown. It appears uipickfiles only allows one single extension per type...

Douglas Schwarz

Ravi, I actually worked on that a while ago, but got busy with other things and didn't quite get it working. I will try to get back to it this week.

Ravi Goyal

Doug, great function! I only struggle as the function does not recognize File Shortcuts (.ink) so I cant access certain data, or only if I try to find the path and copy it by hand. Any idea how to fix that problem so shortcuts will work?

William Thielicke

Hi, my FEX contribution (PIVlab) heavily relies on uipickfiles for data import. Someone also just reported that strange things happen in uipickfiles in r2015a, and I am very glad to see that Douglas seems to have found a solution already...! I'll check it out now.

Douglas Schwarz

Dan, thanks, but I just finished installing R2015a and checked it out. They changed the behavior of dir again (slightly). You can fix the problem just by changing one line. Change the line (on or near line 186)

dir_picks = dir(' '); % Create empty directory structure.

to be

dir_picks = repmat(dir(char(127)),0,1); % Create empty directory structure.

and that will work forever (I hope!).

Dan K

Doug. Quick update.. It is only when the output is set to struct that this bug happens. I made a quick workaround by changing the code around line 611:

% Compute desired output.
switch prop.output
case 'cell'
out = full_file_picks;
case 'struct'
out = cell2struct(full_file_picks,'name',1);

for ientry = 1:numel(out)
tmp = dir(out(ientry).name);
out(ientry).date =;
out(ientry).bytes = tmp.bytes;
out(ientry).isdir = tmp.isdir;
out(ientry).datenum = tmp.datenum;
% out = dir_picks(:);
case 'char'
out = char(full_file_picks);
case 'cancel'
out = 0;

Douglas Schwarz

Dan, thanks for letting me know. I don't have R2015a yet, but as soon as I get it I'll check this out and fix whatever went wrong. - Doug

Dan K

It seems to me that R2015a has broken uipickfiles. It appears to always return all the files in a directory. Can anybody verify this?

Muhammad Hussain

Hi Mr. Anderson,

This is an excellent tool.
Can you please tell that how could I rename the file inside any folder with that folder name.
And how could I create a new folder and add my renamed files in it.
And display my files as a list.

I want the above mentioned functions in addition to this tool.Please give me some hints to add these features.


Douglas Anderson

This is a fantastic utility. I'm a bit confused about 'FilterSpec', 'REFilter', and 'Type'. If you want to have results of two filters displayed at the same time, such as all '*.xls' and '*.xlsx' files, is the only way to do that through the REFilter? Thanks for a great function.

Douglas Schwarz

Dan K,
A favorites list is a great idea and I'm working on it. Also, you're right that the recent list fills up fast with intermediate folders so I've decided to put only destination folders in that list; I think that would be more useful. Thanks for the suggestions!

Molly Rossow

Dan K

This is a fabulous tool. One "feature request" I would love to see is a favorites list. The recent list is great, but since it tracks every folder visited, it can fill up fast with the intermediate folders needed to navigate to your new destination. Given that I frequently need to shift between widely separated directories on network shares and local drives, having a favorites that I could just use to hop to at least the approximate location would be great!



Great improvements over the Matlab function!


Never mind! I'm an idiot, figured out what I was doing wrong

Ryan Edwards

Douglas Schwarz


Sorry for the delay -- somehow I missed your question.

Yes, you can show only folders by entering '^' as the regular expression filter. That will cause the program to display only files that begin with nothing. Since no file has no name and folders are exempt from RE filtering (by default), only folders will be displayed.


I realize that's a bit of a hack so I will consider adding such a feature.


Elliott Liggett

This is a great replacement for the honestly awful built-in file box.

To hide hidden files ("dot files"):
uipickfiles('REFilter', '^[^\.]', 'REDirs', true)



Hi Doug!

This is a great tool!

Is there some way that I could have the function only show folders (i.e. similar to uigetdir)?

Rody Oldenhuis


Douglas Schwarz

Philip, there is currently no way to invert the meaning of the filter to exclude items, but it could be done with a checkbox to indicate it. Let me see if I can fit it in somewhere.

For now, it seems like you could just filter on "new".

andres ferrer

Philip Pavey

Philip Pavey

Instead of filtering for a certain string contained within a folder title, is it possible to omit folders with this string from the list?

For example, I have a folder with 10 folders where 7 contain information I do not want and the string "old" in the title. I would like to show only the 3 folders containing "new" in the folder title.

Is there a way to construct the filter criteria to achieve this?


So useful. Thank you

Douglas Schwarz

Jesse, thanks for the very good suggestion.

Jesse Hopkins

Thanks for this useful tool! One quick note, around line 205 you use exist(..,'file') and exist(..,'dir'). I've found these to be problematic, as exist will return true if it finds the input anywhere on the matlab path.

This actually did cause an error in my case, when I passed in a directory called "Workspace". The directory had been deleted, however exist('Workspace','file') returns true due to workspace.m in the matlab install directory. The subsequent call do dir returned an empty matrix, causing an assignment error.

I've found the following functions more reliable for performing isdir/isfile type operations:
function x = myisdir(str)
x = false;
tmp = dir(str);
if length(tmp) > 1 % if str is a dir, then tmp will always contain at least '.' and '..'
x = true;

function x = isfile(str)
x = false;
tmp = dir(str);

if ~isempty(tmp) && length(tmp) == 1
if ~tmp.isdir
x = true;



A great tool! I use this all the time and just finally got around to rating it. Thanks for sharing this.

Great file!
A great addition would be to make it so that it could also pick files remotely using FTP.

Douglas Schwarz

iman, this question belongs on the newsgroup, but I will answer anyway.

Your error is that n is not an image, but just a string containing the image file name. You must load the image first:

[filename,folder] = uigetfile(...);
im = imread(fullfile(folder,filename));


I use uigetfile to upload image from file in matlab GUI. I don't got any problem with this but when i try to save the image i got error, plez can someone help me.

this is my code

n=uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';... '*.*','All Files' },'Testing',...'C:\Users\norfadhilah\Application Data\Desktop\Testing');

imwrite (n,'myimage.jpg')

Matthew Arthington

Doug and Andrew,

An idea: If displaying information on date and size was very important, perhaps you could use a colormap to shade the background of each file according to its size and/or date, and then only a scale (log scale for size?) would have to be included in the figure window.


Thanks. As long as the sorting works then I'm happy with it. It just wasn't clear that was happening since the values weren't displayed.

Douglas Schwarz


No, they aren't supposed to be displayed. I realize that it's not ideal, but there are two problems with displaying them. (1) There's not enough room. Remember, we have to display both the list of files on the left and the chosen files on the right. To display additional information would simply make the figure too wide. (2) It would be difficult (maybe impossible) to get multiple columns to line up without using a monospaced font. A monospaced font would take up even more room and just exacerbate problem 1.

Those are my reasons, but I will think about your request and if I can come up with a way to do it without sacrificing appearance or functionality I'm not opposed.



Thanks for the quick updates. One other request or possible bug fix, in the window it gives options to sort by Date and Size, but date and size aren't displayed for any of the files. Are they supposed to be? I'm running it in Matlab 2012a on a Macintosh. Thx.

Douglas Schwarz

Chris, I uploaded a new version that deals with the "My Documents" issue.

Douglas Schwarz


I hadn't noticed this before, but I see what you mean. I think I know a way to check if the directory is real or a figment of Window's imagination (like "My Documents" is) so I should be able to drop "My Documents" from the list automatically. Note that "Documents" also appears so if you just select that all is well, but I agree that if "My Documents" doesn't represent a valid choice it shouldn't appear at all. I will work on it and update uipickfiles soon. Thanks for the report.


Hey Doug,

I am using this function with Windows 7. When you navigate to your 'My Documents' folder, nothing is displayed because the actual folder name in the directory path is 'Documents'. If I edit the 'My ' out of the path displayed then the directory contents appear. Is there a place in the code where i could search the new directory path for 'My Documents' in order to replace it with 'Documents'? Other directories such as 'My Received Files' do don't exhibit the same error.

Douglas Schwarz

Bryan, that's interesting. Back when I first wrote this function, that was not an error, but at some point TMW changed textscan and I didn't notice. Anyway, I just submitted a fix. Thanks for the report!


Douglas, great function. I noticed a bug while using on a PC. When I back out all the way to My Computer and open a new drive. I get an error at line 1299 for calling textscan with the first input empty.

Douglas Schwarz

Andrew, I'm glad to oblige. I just submitted a version that cancels with a press of the escape key. Thanks for the suggestion.


Love the program. Only thing I'd like is if you press escape on the keyboard it be the equivalent of clicking the cancel button (it's the only thing uigetfile has up on this one). Thanks.

Douglas Schwarz

I just uploaded a new version that is resizable and remembers the size and position so you can choose any size you want.

Lube F

Excellent function. One (stupid) question: I've got long file names and would like the gui window to open maximized so that I can see them fully. Is this possible? Could be incorporated if necessary?


Thanks a lot ! Very time saving for me

Douglas Schwarz

Horia, you must have another file called uipickfiles.m because that line of code simply does not exist in my function. Run 'which uipickfiles -all' to help sort this out.


I re-downloaded the file.
When executing the function, I get:

??? Error using ==> setappdata
Invalid object handle

Error in ==> uipickfiles at 382
setappdata(hgui, 'sequencer', 1); %default style

Sorry, but I can't figure why this happens.

Douglas Schwarz

Horia, try downloading it again because I just downloaded it myself to be sure and setappdata is not in there. The downloaded uipickfiles.m is exactly as it should be.


It appears in the downloaded file.

Douglas Schwarz

Horia, I don't know what function you have because I don't use setappdata in my function at all.


On R2008a,I get the message:
??? Error using ==> setappdata
Invalid object handle

Error in ==> uipickfiles at 382
setappdata(hgui, 'sequencer', 1); %default style


That's an excellent tool. All it's really missing is cut/copy/paste functionality. Sounds feasible too.

Douglas Schwarz

Md. Niazul,

Try replacing the calls to sort in lines 1025-1037 with sort_nat. It might do what you want. It is available from


Md. Niazul

I am using this function uipickfiles. But my problem is, GUI of this function does not show the file names in the same order ,as they are in the folder.
In the folder my files look like:


but the GUI of this function is showing like this:

how can i fix the problem ..Could anyone help please.??

Zhijiang Wang

Good Job! Good man!


Douglas Schwarz

Hi Asaad,

Are you using my function, uipickfiles, or the built-in function uigetfile? If mine, please let me know what arguments you are using.


Asaad Said

Hi Douglas,

I'm having a problem reading many files (>780 files) using uigetfile function. the function works fine if I read less than 780 files. I'm getting the following error message
"File not found. Please verify the correct file name was given"

I looked at this error online, but didn't find any solution online on Mathworks website.
I appreciate if you can help or provide a link for this issue


Matthew Arthington

This is something TMW should have made a long time ago.

Thank you for sharing it, it works very well.


That was exactly what I was looking for. Thank You!


Very good...



Thanks very much. This is a great tool that I've incorporated into my GUIs when I need to select a large number of files.

Debanjan Goswami


I should mention one other thing. The directories and files I am accessing are on a network drive...not sure if that makes a difference. (the network drive is specified in the filter property value)

Douglas Schwarz

gozer, I'm not sure what you mean. You should be able to navigate around the file system and add files to the Selected Files list from multiple directories. When you say 'pick list', which one do you mean, the list on the left or the one on the right? The one on the left should show the contents of one directory at a time while the list on the right should show every file you have added to it until you press 'Done'. Please clarify. - Doug


Would like to add my kudos to your work. excellent job....with one question;
I have a need to be able to select files for various directories. But it seems once a select files from one directory, then try to level-up to another it does not refresh the 'pick list'. Am I doing something wrong?

William Thielicke

Hey cool, thank you very much!!

Douglas Schwarz

I just fixed it and uploaded the new version -- it should appear soon. Thanks for the bug report!

William Thielicke

Very nice, I especially like the possibility to sort the filenames manually in the GUI. But when I set 'output' to 'struct' (that is what I need for my application), it doesn't care anymore about manual sorting. Is there a way to fix this problem?

Andrey Rubshtein

Great! No Guide, does the job, very useful.

Amjad Elshenawy

Very useful



This would have saved me a lot of programming, well it will even save some time in future....perfekt, classic 5 stars for SUPERUSEFUL

Nathan Greco

Very useful, especially when loading in multiple files at one with a regexp filter. Thanks a lot!

Douglas Schwarz

J W, what platform are you using and what kinds of files are those? Do the hidden files somehow pair up with non-hidden versions so you have both ._abc.txt and abc.txt? It would be easy to add a feature so that hidden files are not displayed in uipickfiles as long as we can identify them. Tell me more.


Actually, I just found a workaround. At every designation of 'filenames' I follow it with a series of loops testing each filename to see if it is preceded by '._' My supplement to the code is working well if anyone needs to have hidden files removed from file lists.


Great File! One quick question though - how might I go about removing hidden files from file lists? I notice that when I have hidden files in the same directory as the images I am trying to retrieve, hidden file versions with prefix '._' appear first making file selection very non-intuitive. Any solutions?

Douglas Schwarz

Skip, you can double-click on a file and it will be added to the list immediately. That may be sufficient for your purposes, but I will look into your suggestion.


Very useful. Thank you!

Is it possible to have files added to the list in Ctrl+click order? This would avoid the need to sort files after selecting.

Rene Michels

Great Job,

THX for sharing! It really helps me out!!

Ben Bratton

Excellent code. Very helpful for myself and colleagues. We work with image processing and this greatly simplifies our lives.

Thomas Ibbotson

This looks like just what I need. However I was getting an error when I first tried to use it. It appears that if you specify a filter which returns no files, there is an error:

??? Error using ==> vertcat
CAT arguments are not consistent in structure field number.

Error in ==> uipickfiles>filtered_dir at 762
d = [ddot1;ddot2;dfiles(index1);ddir(index2)];

Error in ==> uipickfiles at 164
fdir = filtered_dir(full_filter,re_filter);

I fixed this by adding these lines:

762 if ~isempty(dfiles)
763 d = [ddot1;ddot2;dfiles(index1);ddir(index2)];
764 else
765 d = [ddot1;ddot2;ddir(index2)];
766 end

It might not be the best way to do it, but it works for me.

Joe Spernyak

Great for Queue'ing up lots of files/datasets for overnite processing.

Jeff Meganck

Incredibly useful, very well written program. I have incorporated this program into almost all of my own scripts. I just upgraded to R2007b(7.5.0) and started to get the following problem:

??? Subscripted assignment between dissimilar structures.

Error in ==> uipickfiles>add at 353
dir_picks(end + 1) = dir_pick;

??? Error using ==> waitfor
Error while evaluating uicontrol Callback

The fix was easy. Add 'datenum',[] at the end of line 171 so that it reads:
dir_picks = struct('name',{},'date','','bytes',[],'isdir',[],'datenum',[]);

B. Andre Weisntock

I needed an intuitive way for a non-MatLab user to load multiple directories into a MatLab stand-alone application and this product was EXACTLY what was needed. Perfect. Many thanks Doug!

Oleksandr (Alex) Dzyubak

I am working on image processing and for me that is usual practice to have more than 100 images in a set. The native MATLAB utility uigetfile does not support that at the moment.
In fact, uipickfiles DOES. Which is more, it works in Linux and Windows and for R2006b and R2007a. Thanks Douglas!!! Nice product!


Elakkat D

reallay useful tool

Douglas Schwarz

Patrick, yes it could be done. Email me and we'll discuss it. -- Doug

Patrick Naulleau

Any chance of getting a non-nested function version of this allowing it to work in earlier versions of Matlab?

Chris K

Thank you for updating it! I am thrilled to be able use it!

Douglas Schwarz

TMW changed the struct returned by dir in R2007a. I have updated uipickfiles accordingly. (It will still work with older versions of MATLAB.) Thanks for the report.

Chris K

The interface looks great, but I can't use it because of the following error and others.

??? Subscripted assignment between dissimilar structures.

Error in ==> uipickfiles>add at 353
dir_picks(end + 1) = dir_pick;

??? Error using ==> waitfor
Error while evaluating uicontrol Callback

I am running:
MATLAB Version (R2007a) on Mac OS X

Oleksnadr Dzyubak

Just Great!!!
I work on Linux where uigetfile is buggy.
The "uipickfiles" is an excellent workarround.
Many thanks!

Johann Boleininger

Very useful, many thanks.

Lennaert Klerk

Great!! This saved me so much time and is going to be used a lot by me and my colleagues....

Laszlo Totthfalusi

Smashing, cool

Scott Miller

Sweet. This saves me a lot of time; I was going to have to write one of these myself. I like that it is written completely in m script; there is really no point in writting such an interface as a dll if you don't have to, and this makes is easy to customize. It also doesn't seem to to have that "where's my dialog box?" effect of uigetfiles, (NOT uigetfile!), where occasionally, randomly, the dialog box will "open" with the window closed on startup. My only complaint as a windows user is uipickfiles has that funny UNIX smell to the UI (e.g., "..\" instead of an up arrow, files are sorted by case and then alphabetically instead of alphabetically), but hey, you can't have everything, and the script is right there if you want to change something.

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!