How do I run the WHAT command recursively in MATLAB R2007b?

1 view (last 30 days)
I want the output of WHAT on a folder and all its subfolders. Currently WHAT only provides the output for the specified folder.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Dec 2021
Edited: MathWorks Support Team on 13 Dec 2021
There is no single MATLAB command that will give you all the MATLAB related files in a directory and its subdirectories, but it is possible to process the
output of the GENPATH command to produce the desired result.
The MATLAB command GENPATH returns a string consisting of a folder and all its subfolders separated by the PATHSEP:
mkdir a
mkdir a\b
p = genpath('a')
produces the output:
p =
a;a\b;
Running REGEXP on p with the 'split' option produces a cell array of
the individual subdirectories:
s = regexp(p, pathsep, 'split')
which produces the output:
s =
'a' 'a\b' ''
(Note that there is an empty string at the end because of that final trailing semicolon in p)
We can now loop through the cell array s and run the WHAT command on each folder:
for k=1:length(s)-1 % subtract one to skip over that last empty string
what(s{k})
end
The file recursive_what.m combines the above steps into a MATLAB function.
Caveats: the 'split' option to REGEXP is new in 2007b.
You can get more information about GENPATH, PATHSEP and REGEXP from inside MATLAB by typing
doc genpath
or
doc pathsep
or
doc regexp
or by going to the following URLs

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Products


Release

R2007b

Community Treasure Hunt

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

Start Hunting!