4.21429

4.2 | 14 ratings Rate this file 46 Downloads (last 30 days) File Size: 3.82 KB File ID: #8682

DIRR (find files recursively filtering name, date or bytes)

by

 

07 Oct 2005 (Updated )

Lists files recursively filtering name date and/or size. Output can be set as name date and/or size.

| Watch this File

File Information
Description

DIRR

Lists all files in the current directory and sub directories recursively.

[LIST] = DIRR(PATH)
Returns a structure LIST with the same fieldnames as returned by LIST = DIR(PATH)

PATH can contain wildcards * and ? after the last \ or / (filename filter)

The content of each directory in PATH is listed inside its 'isdir'field with the same format. The 'bytes' field is NOT zero but the sum of all filesizes inside the directory.

[LIST,BYTES] = DIRR(PATH)
BYTES is a structure with fields 'total' and 'dir'. 'total' is the total size of PATH. 'dir' is a recursive substructure that contains the same fields ('total' and 'dir') for the subdirectories.

[...] = DIRR(PATH,FILTER)
Lists only files matching the string FILTER (non case sensitive regular expression).

N.B.: FILTER is optional and must not be equal to a fieldname ('name' or 'date' ... will never be interpreted as filters)

[LIST,BYTES,FIELDOUT] = DIRR(PATH,FIELDIN, ...)
FIELDIN is a string specifying a field (of the structure LIST) that will be listed in a separate cell array of strings in FIELDOUT for every file with absolute path at the begining of the string.
Multiple fields can be specified.

[LIST,BYTES,FIELDOUT] = DIRR(PATH,FIELDIN,FILTER, ...)
Only files for which FIELDIN matches FILTER will be returned.

Multiple [FIELDIN, FILTER] couples can be specified. Recursion can be avoided here by setting 'isdir' filter to '0'. For bytes, numeric comparison will be performed.

EXAMPLES :

DIRR
Lists all files (including path) in the current directory and it's subdirectories recursively.

DIRR('c:\matlab6p5\work\*.m')

Lists all M-files in the c:\matlab6p5\work directory and it's subdirectories recursively.

Music = DIRR('G:\Ma musique\&Styles\Reggae\Alpha Blondy')

Returns a structure Music very similar to what DIR returns but containing the information on the files stored in subdirectories of 'G:\Ma musique\&Styles\Reggae\Alpha Blondy'.

The structure Music is a bit difficult to explore though.See next examples.

[Files,Bytes,Names] = DIRR('c:\matlab6p5\toolbox','\.mex\>','name')

Lists all MEX-files in the c:\matlab6p5\toolbox directory in the cell array of strings Names (including path). Note the regexp syntax of the filter string. Bytes is a structure with fields "total" and "dir". total is the
total size of the directory, dir is a recursive substructure with the same fields as bytes for the subdirectories.

[Files,Bytes,Names] = DIRR('c:\toto'...
      ,'name','bytes','>50000','isdir','0')

Lists all files larger than 50000 bytes NOT recursively.

[Files,Bytes,Dates] = DIRR('c:\matlab6p5\work','date','2005')

Lists all dates of files from year 2005. (With path in front of date in the cell array of strings Dates)

MATLAB release MATLAB 7.0.4 (R14SP2)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
13 Aug 2014 weiqiang gao  
01 Aug 2012 Alan

dirr('C:\Users\Jim\*.mp3') doesn't work

31 May 2012 Josiah McClurg

For those of you who want a more generic version, see my comment on http://www.mathworks.com/matlabcentral/fileexchange/32036-dirwalk-walk-the-directory-tree

19 Apr 2012 pietro

It's a really good function, but I have a problem for storing the file list in a variable. I get only the file list of the folder and not of the file stored in the subdirectories.
As example:
dirr(folder) works
[file_list byte]=dirr(folder) doesn't work as the previous example.

May anyone be so kind to explain to me what should I do for getting the file list?

26 Mar 2012 Liu Ning  
24 Oct 2011 Pei JIA

I failed to use this dirr.m in Octave3.2 under Unbuntu 11.04 .

octave:6> dirr ('./', 'name')
warning: function name `DIRR' does not agree with function file name `....../dirr.m'
error: regexpi: internal error calling pcre_exec
Error code from pcre_exec is -24
error: called from:
error: ....../dirr.m at line 225, column 9

But, this type of error never happens using Matlab R2010b, under Windows7.

Did anybody else meet the same problem before?

Cheers
Pei

21 Jun 2011 Mathieu Boutin

Thank you very much for your function, you made me save a lot of time!

27 Feb 2011 T. R.  
23 Feb 2011 Alceu Costa  
13 May 2008 Dimitri Shvorob

.. and here's the competitor that met the challenge:

http://www.mathworks.co.uk/matlabcentral/fileexchange/loadFile.do?objectId=19550&objectType=FILE

13 May 2008 Dimitri Shvorob

It really needs to return paths, not just file names. (Of course, this is not needed with DIR). DIRR handled a task that FUF (another FEX submission) gave up on, but without paths, the output is useless :(

29 Jan 2008 Peter Stubberfield

I coulddn't get it to work on R2006b, with a simple query like:
dirr('d:/ap_vehicle_validation/*.dat')

I get all files, not just .dat files.

04 Jul 2007 michael sch

very good
thank you
from
www.meciba.com

07 May 2007 Tanar Dity  
17 May 2006 Mark Bolding

need to change \ to / on "other" operating systems

20 Apr 2006 Matte Ali  
20 Dec 2005 gok gok  
Updates
21 Jul 2006

Update for Matlab 7 compatibility

Contact us