Code covered by the BSD License  

Highlights from
Recursive directory listing

5.0

5.0 | 11 ratings Rate this file 87 Downloads (last 30 days) File Size: 2.61 KB File ID: #19550

Recursive directory listing

by Gus Brown

 

11 Apr 2008 (Updated 14 Apr 2008)

Directory listing with a difference, supports directory wildcards.

| Watch this File

File Information
Description

Lists the files in a directory and its sub directories.

Ok, so there are many functions like this one already on the file exchange, but this one uses a slightly different wildcard naming system that some people may find useful.

For example,

rdir('C:\Program Files\Windows*\**\*.dll');

will find all dll files in the directories starting with 'C:\Program Files\Windows' and all the dll files in the sub directories below them.

One can filter the list based on the file size and date.

Using the function to find files modified sometime today in the windows directory

rdir('C:\Win*\*','datenum>floor(now)');

Include the sub directories.

rdir('C:\Win*\**\*','datenum>floor(now)');

Or you could use it to find all the no zero-byte processed csv data files for the data recorded in April 2008.

rdir('data\test_200804*\csv\*.csv','bytes>0');

this finds files like...
data\test_20080401\csv\08h00.csv
data\test_20080401\csv\16h00.csv
data\test_20080402\csv\08h00.csv
data\test_20080402\csv\16h00.csv

Acknowledgements
This submission has inspired the following:
Find 'orphaned' m-files, Find repeated m-file names, Recursive directory walk with -exec (UNIX type), Find Repeated Files, (Sub)Folders directory, Recursive directory listing - Enhanced RDIR
MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
13 May 2008 Dimitri Shvorob

Great job! Did what neither FUF nor DIRR (earlier FEX submissions) managed to do, and surprisingly fast, too.

12 Jun 2008 Dennis Olly

FUF was great, but failed on folders with a '.' in the name, eg '\recon_P20992.7\'. Rdir is excellent!
 

16 Jul 2008 Imaging Coderguy

I used FUF extensively in the past, and though it did the job, its slowness and quirks were problematic. RDIR on the other hand is so slick and well-made that it may as well be a mathworks-made function. Great work!

29 Jul 2008 Phillip Feldman

Excellent! Just what I was looking for.

The double star syntax is a bit strange. I'd like to suggest that a slightly cleaner and more flexible mechanism for controlling the recursive searching would be an optional argument that specifies the maximum folder depth of the search.

22 Jan 2009 Ashish Uthama  
24 Jun 2009 Oleg Komarov  
06 Aug 2009 Bart Geurten  
02 Dec 2009 Kevin

Very Useful Function.
One thing I have noticed when using this function is that the results are not unique. The files that are returned seem to be repeated based on how many subdirectories deep they are. This issue is easily fixed by running unique on the results.

06 Sep 2010 Mathias Lindner

A very helpful script. After some troubles in the beginning using the inconvenient double-star '**' everything is perfect now.

23 Feb 2011 pietro

The best!

10 Jun 2011 pietro

This function is great but unfortunately with many subfolders it has some problems. For example I have typed this:
files=rdir('C:\Users\ml\Documents\virtual\model\Multibody output signals')

and I got:
C:\Users\ml\Documents\virtual\model\Plot_1_SYSTEM;Time;;lower housing (NAUO9);xdd.txt

insted with uigetfile I got:
C:\Users\ml\Documents\virtual\model\Multibody output signals\Plot_1_SYSTEM;Time;;lower housing (NAUO9);xdd.txt

With less subfolders I don't get this problem.

14 Jun 2011 Thomas Vanaret

@ pietro : there is indeed a bug in the way the displayed path is built in rdir function, in the "if isempty(wildpath)" statement.

Output name is built only from "prepath" and "D(ii).name" (on line 87). "postpath" is always omitted whereas it can be the parent directory name.

22 Jun 2011 pietro

Hi Thomas,so in which way can it be fixed?

15 Jul 2011 Thomas Vanaret

@ Pietro and other RDIR users :
I just submitted an enhanced version of RDIR function that fix bug on returned path an add some new features.

See "Recursive directory listing - Enhanced RDIR" below / File ID: #32226

30 Nov 2011 Mike Sheppard  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
path Gus Brown 22 Oct 2008 09:57:21
directories Gus Brown 22 Oct 2008 09:57:21
files Gus Brown 22 Oct 2008 09:57:21
unusual Gus Brown 22 Oct 2008 09:57:21
recursion Gus Brown 22 Oct 2008 09:57:21
directory Gus Brown 22 Oct 2008 09:57:21
difference Gus Brown 22 Oct 2008 09:57:21
utilities Gus Brown 22 Oct 2008 09:57:21
difference Jan 26 Apr 2010 03:55:39
directories Jan 26 Apr 2010 03:55:41
directory Jan 26 Apr 2010 03:55:43
files Travis Greene 11 Nov 2010 17:09:06

Contact us at files@mathworks.com