View License

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

» Watch video

Highlights from
Recursive directory listing - Enhanced RDIR

5.0 | 19 ratings Rate this file 122 Downloads (last 30 days) File Size: 9 KB File ID: #32226 Version: 1.5

Recursive directory listing - Enhanced RDIR



14 Jul 2011 (Updated )

Files and directories listing, including recursive and other special features

| Watch this File

File Information

Enhanced version of RDIR function, fixing some bugs and adding some features.

- Basic use is similar to Matlab "dir" function, which allow you to list files and directories in a given path :

  rdir([matlabroot, '\*.txt'])

When asked, rdir output structure is the same as dir output structure :

  d = rdir([matlabroot, '\*.txt'])

- As initial RDIR function, you can use a double wildcard (**) to list files in all subdirectories from a given path :

  rdir([matlabroot, '\**\*tmpl*.m'])

- And also use a filter entered as 2nd argument to refine your search :

  rdir([matlabroot, '\**\*tmpl*.m'], 'bytes>0')

This enhanced version of RDIR allow you to define filter on all fields of returned structure and also to use functions like "regexp" or "strfind" on "name" field. You can also use a function handle working on dir-like structure to refine the search.

- You can then add as 3rd argument a path to remove from beginning of "name" field of each listed item :

  rdir([matlabroot, '\*.txt'], '', 'C:\Program Files\')
All in : C:\Program Files\
  76 kb 02-Aug-2007 16:03:52 MATLAB\R2007b\license.txt
 631 b 02-Aug-2007 15:18:42 MATLAB\R2007b\patents.txt
 413 b 04-Aug-2007 12:16:36 MATLAB\R2007b\trademarks.txt

- ".svn" directories created by SubVersion (SVN) are excluded from the recursive listing.

See published examples for more details on how to use all RDIR capabilities.


Recursive Directory Listing inspired this file.

This file inspired Dicom Operator Esme Process, Orphan Libs(Test, Trgt), Rdir Dos, and Youemel.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
16 Nov 2016 Serge Kogan

17 May 2016 Adi Navve

Adi Navve (view profile)

Nice and simple. Well done.

06 May 2016 Cristina Domnisoru

Thank you :) you've saved me from using the file explorer to delete files

06 Jan 2016 Noam Greenboim

Very useful, I don't understand why this file wasn't adopted by Mathworks in the original version of Matlab.

14 Sep 2015 Ben Kang

Very good and easy-to-use function!

17 Aug 2015 Tom Clark

Excellent, does exactly what it says on the tin and saves a bunch of time writing recursive functions.

A little slow, but it might just be my OS which is kind of cantankerous at the moment, so I'll go ahead with the full 5*. Thanks for your contribution!

29 Mar 2015 Noam Greenboim

Very useful, works great

02 Jan 2015 Muhammad Naveed

not able to use it for mp3 files listing from D:\
kindly help me

Comment only
20 Dec 2014 Liron

Liron (view profile)

04 Aug 2014 Thomas Vanaret

@KRUNAL : use "*" to match any folder from the same path.
Use "**" to match any folder and subfolders from the same path.
See examples for more help

Comment only
24 Jul 2014 KRUNAL

KRUNAL (view profile)


Comment only
24 Jul 2014 KRUNAL

KRUNAL (view profile)

Hey andrew, how did you manage to make it find multiple files with same name which are in different folders?

Comment only
09 Jan 2014 Alexandre De Barros

05 Feb 2013 Joao Henriques

Joao Henriques (view profile)

21 Jan 2013 Steve Goley

Nice implementation and it's nice that it has the same output as "dir". My only grep is that it can be somewhat slow when you're recursing through really dense file structures. This could be my file system or the fact the implementation is pure MATLAB, which is nicely portable, but it would be nice to parse sections out to an option mex file for extra speed.

06 Dec 2012 Ron Lu

Ron Lu (view profile)

Thanks, very useful with regexp support.

14 Nov 2012 Xiaohu

Xiaohu (view profile)

04 Oct 2012 Jaroslaw Tuszynski

Very good - I use it all the time.

26 Apr 2012 Julian

Julian (view profile)

Thanks, that was really useful in a selective by-size backup

23 Jan 2012 Thomas Vanaret

Thank you Alan for your suggestion.
Problem has been fixed in new version available (2.2).

Comment only
27 Dec 2011 Andrea

Andrea (view profile)

Sorry... manage to have it working!

27 Dec 2011 Andrea

Andrea (view profile)

Very useful indeed!
I am not sure if I am missing something, but unfortunately I am not able to make it finding multiple files with same name (even if in different folders). This would be a great improvement!

19 Dec 2011 Alan Jennings

Alan Jennings (view profile)

Works great and saved me a lot of time.
A suggested improvement, instead of looking at the file size to identify directories, use the isdir flag.
Line 286: if D(ii).isdir %sz<0,
Change display to allow for 0b files
Line 291-293:
ss = max(0,min(4,floor(log2(sz)/10)));
disp(sprintf('%4.0f %1sb %20s %-64s ',...
sz/1024^(ss+eps),pp{ss+1}, datestr(D(ii).datenum, 0), D(ii).name));

Comment only
19 Dec 2011 Alan Jennings

Alan Jennings (view profile)

29 Nov 2011 Hakon

Hakon (view profile)

extremely useful - thanks!

15 Jul 2011 1.1

Licence update

22 Jan 2012 1.3

Version 2.2
Fixing bug on display with 0b files;
Specific display when no file match filter;

20 Jan 2014 1.4

Version 2.3 :
Adding improvements suggested by X. Mo :
- function handle as TEST input
- code optimisation (avoiding loop)
Fixing possible bug when using a wildcard at the beginning;
Common path as 2nd optionnal output;

27 Jan 2014 1.5

Examples script update only

Contact us