View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.7 | 3 ratings Rate this file 6 Downloads (last 30 days) File Size: 2.15 KB File ID: #16216 Version: 1.0



Bob Hamans (view profile)


03 Sep 2007 (Updated )

Returns a directory listing based on a regular expression

| Watch this File

File Information

REGEXPDIR Gives a directory listing based on a regular expression REGEXPDIR(ROOTDIR, REGEXP) gives a directory listing of the directory ROOTDIR based on the pattern specified by the regular expression REGEXP.

REGEXPDIR(ROOTDIR, REGEXP, RECURSIVE) By default REGEXPDIR traverses all subdirectories recursively. This behaviour can be controlled by supplying the optional boolean RECURSIVE. Setting this to 'false' will limit the function to the directory specified in ROOTDIR.

 rootdir = 'C:\';
 expstr = '^.*\.exe$';
 dirlist = regexpdir(rootdir, expstr);

The above example will return any EXE files on the C-drive.

By default REGEXPDIR searches case insensitive. To make it case senstitive please specify it in the regular expression by adding '(?-i)' to it. Ommitting to specify the beginning '^' and ending '$' of the regular expression may result in unexpected behaviour.

Have a look at the source code for more information. For more info on this function and how to use it, bug reports, feature requests, etc. feel free to contact the author.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
14 May 2014 Christopher

Works great out of the box. The optional recursive flag is particularly helpful. Thank you for your contribution.

07 Jun 2013 Richard Moore

Richard Moore (view profile)

Great function! I often write scripts that sort through files and strings with wildcards are often not expressive enough to filter compactly. Your recursive option is handy, too. It would be nice if the output were a struct array like dir returns instead of a cell array, though.

17 Dec 2007 Felix Biessmann  

Contact us