view .m files in a folder (including subFolders) i

2019-08-30 06:13发布

问题:

I have a Folder Factors inside Project folder. (all inside MyDocuments/Matlab). I need the list of all .m files in the folder FACTORS. Factors has subFolders and these subFolders hold all the .m files. Any suggestions?

Directory Design ->

Project...
    Factors ... etc
       subFol1 (has .m files)
       subFol2 (has .m files)
    ...

回答1:

I have solved a similar problem.On Windows platforms, ,Like this:

pathName='.... \FACTORS';%your path
[stat path]=dos(['dir ' pathName '\*.m /s /B >path.txt'] );
name=importdata('path.txt');
delete path.txt

Now,you can see all files which matches the conditions is in the cell array "Name"



回答2:

This function would be useful. It will recursively search folders, executing a user defined function on each directory. You will need to write your own function to list all .m files in the current directory.