5.0

5.0 | 5 ratings Rate this file 35 Downloads (last 30 days) File Size: 6.91 KB File ID: #32226

Recursive directory listing - Enhanced RDIR

by Thomas Vanaret

 

14 Jul 2011 (Updated 22 Jan 2012)

Files and directories listing, including recursive and other special features

| Watch this File

File Information
Description

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 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 example for more details on how to use all RDIR capabilities.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Recursive directory listing

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
29 Nov 2011 Hakon

extremely useful - thanks!

19 Dec 2011 Alan Jennings  
19 Dec 2011 Alan Jennings

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));

27 Dec 2011 Andrea

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!

27 Dec 2011 Andrea

Sorry... manage to have it working!

23 Jan 2012 Thomas Vanaret

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

26 Apr 2012 Julian

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

Please login to add a comment or rating.
Updates
15 Jul 2011

Licence update

22 Jan 2012

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

Tag Activity for this File
Tag Applied By Date/Time
dir Thomas Vanaret 15 Jul 2011 09:43:41
recursive Thomas Vanaret 15 Jul 2011 09:43:41
file Thomas Vanaret 15 Jul 2011 09:43:41
directory Thomas Vanaret 15 Jul 2011 09:43:41
listing Thomas Vanaret 15 Jul 2011 09:43:42
utilities Thomas Vanaret 15 Jul 2011 09:43:42
path Thomas Vanaret 15 Jul 2011 09:43:42
files Thomas Vanaret 15 Jul 2011 09:43:42
directories Thomas Vanaret 15 Jul 2011 09:43:42
filter Thomas Vanaret 15 Jul 2011 09:43:42
svn Thomas Vanaret 23 Jan 2012 09:28:24

Contact us at files@mathworks.com