1.0

1.0 | 1 rating Rate this file 30 downloads (last 30 days) File Size: 2.35 KB File ID: #22544

Recursive directory walk with -exec (UNIX type)

by Ashish Uthama

 

29 Dec 2008 (Updated 29 Dec 2008)

Code covered by BSD License  

Directory walking with input function handle called with each matching file found.

Download Now | Watch this File

File Information
Description

See decription of RDIR (linked in Acknowledgements) for wildcard use.

Calls a function handle for each matching file found.

  rdirExec(ROOT,EXECFUN,OPTEXECFUNARGS)

Recursive directory walk. EXECFUN is a function handle that gets called for each matching file found.The first input argument being the full path of the file, followed by the optional OPTEXECFUNARGS

ROOT is the directory starting point and includes the wildcard specification. Pathnames and wildcards may be used. Wild cards can exist in the pathname too. A special case is the double * that will match multiple directory levels, e.g. c:\**\*.m. Otherwise a single * will only match one directory level.
  e.g. C:\Program Files\Windows *\

EXECFUN is a function handle which takes at least one input argument

OPTEXECFUNARGS are optional input arguments to EXECFUN

Examples:
  
    % To create a file list
    fid=fopen('fileList.txt','wt');
    rdirExec('c:\program files\windows *\**\*.dll',@callBack,fid)
    fclose(fid);

    %The callBack function has the following signature
    function callBack(varargin)
    fileName=varargin{1};
    fid=varargin{2};
    fprintf(fid,'%s\n',fileName);
    end

Acknowledgements

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

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
26 May 2009 Henry

Great concept, but buggy implementation.

Please login to add a comment or rating.
Updates
29 Dec 2008

text indents in desc

Tag Activity for this File
Tag Applied By Date/Time
directory Cristina McIntire 29 Dec 2008 15:55:16
path Cristina McIntire 29 Dec 2008 15:55:16
files Cristina McIntire 29 Dec 2008 15:55:16
utilities Cristina McIntire 29 Dec 2008 15:55:16
find Cristina McIntire 29 Dec 2008 15:55:16
exec Cristina McIntire 29 Dec 2008 15:55:16
directory file path Ashish Uthama 29 Dec 2008 16:54:32
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com