Returns a cell array of all files matching the wildcard expression "refiles" beginning in the root folder "root". Includes subdirectories.
mfiles = getfilenames('c:\','*.m') will return all .m files on the c drive to the cell array "mfiles".
To make this code work for Matlab 2010b as well as other versions for both PC and Mac replace the lines 30 to 34:
Now it will work with version 2010b
No longer works recursively on R2010b, even thought it does on R2010a. I am not sure why.
Useful. Wish Matlab had more builtins for file searching and management, since I write mfiles that have to be used by Windows users (no perl)
Works great... fast as well
Does not work for linux, because it uses the function "ismac" instead of isunix.
Additionally, I do not see why the wildcard should be set to an empty string on a mac, a '*' would make more sense, right?
Why not use the Matlab-original function 'what'? At least for Matlab-related files, it gives you exactly what you want to do with getfilenames.
Very nice. It is surprisingly fast. This will save me a lot of time.
it works well in Matlab2008a(7.6).Thanks for sharing!
Best thing since sliced bread.
Very good. Saved me a lot of time.
Nice file, but one request - Can you rewrite this so that instead of CD-ing between directories, your recursive calls to DIR include the right path information? This way if the program errors or is halted (say, with cntrl-c), you don't end up in some strange directory. This would also make the program more robust to potential network problems, too (eg, such as getting "abandoned" in a stale filesystem if a network drive is suddenly disconnnected after you've CD-ed into it).
If you can do that, I'd give this file a 4 or 5!
Thanks to Kenn Sebesta. His Comments:
Hi, I fixed getfilenames.m to work with Mac. I'm betting it works with
The secret ingredient was `fullfile`, which lets Matlab decide for
Bug fix on line 36. Changed 'cd' to 'root'. Thanks Elena.
Removed the cd to other folders per suggestion. Now, it stays in the folder where it was called. Also added ability to simply return all subfolder names only if a single root folder argument is passed.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.