How can I search a file in MATLAB 7.9 (R2009b)?

1 view (last 30 days)
I would like to look for a particular file in a subdirectory. I only know the root level directory which contains multiple subdirectories. I would like to know how to look for this file recursively and find whcih subdirectory it resides in.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 May 2017
To search for file that are not on MATLAB path, use the DIR command in MS-DOS. For this, use the CD command to the top level directory, and use the DIR command within the DOS command from MATLAB this way:
 
[a,b] = dos('dir /s /b <myfile>*');
filenames = textscan(b,'%s','delimiter',char(10));
filenames = filenames{1};
Here the /s option looks inside subfolder and <myfile> is the file that you are searching for. The /b option ensures that the output is in bare format.
To read more about the DOS command, visit here:
<http://www.computerhope.com/dirhlp.htm>

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Products


Release

R2009b

Community Treasure Hunt

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

Start Hunting!