Recursive Directory Function Execution

version (1.62 KB) by Rodney Thomson
Recurse through all directories executing the supplied function


Updated 22 Jul 2008

View License

Recurses through each directory, passing the full directory path and any extraneous arguments (varargin) to the specified function.

Call Sequence : directoryRecurse(directory, function_pointer, varargin)

IE: To execute the 'rmdir' command with the 's' parameter over 'c:\tmp' and all subdirectories:

directoryRecurse('c:\tmp', @rmdir, 's');

Another useful example, add 'c:\matlab' and all sub directories to the Matlab path:
directoryRecurse('c:\tmp', @addpath);

Cite As

Rodney Thomson (2022). Recursive Directory Function Execution (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!