5.0

5.0 | 11 ratings Rate this file 74 Downloads (last 30 days) File Size: 9 KB File ID: #32226

Recursive directory listing - Enhanced RDIR

by

 

14 Jul 2011 (Updated )

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 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.

Acknowledgements

Recursive Directory Listing inspired this file.

This file inspired Dicom Operator Esme Process and Rdir Dos.

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 (16)
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

24 Jul 2014 KRUNAL

sorry..Andrea

24 Jul 2014 KRUNAL

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

09 Jan 2014 Alex Debarros  
05 Feb 2013 Joao Henriques  
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

Thanks, very useful with regexp support.

14 Nov 2012 Xiaohu  
04 Oct 2012 Jaroslaw Tuszynski

Very good - I use it all the time.

26 Apr 2012 Julian

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

27 Dec 2011 Andrea

Sorry... manage to have it working!

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!

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

19 Dec 2011 Alan Jennings  
29 Nov 2011 Hakon

extremely useful - thanks!

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;

20 Jan 2014

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

Examples script update only

Contact us