File Exchange

image thumbnail

Recursive directory walk with -exec (UNIX type)

version 1.2 (2.25 KB) by

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

1 Download

Updated

View License

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

Comments and Ratings (1)

Henry

Henry (view profile)

Great concept, but buggy implementation.

Updates

1.2

*Fixed 'clear D' bug

1.1

text indents in desc

MATLAB Release
MATLAB 7.7 (R2008b)
Acknowledgements

Inspired by: Recursive directory listing

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video