MATLAB: MATLAB Versions 1 through 13

MATLABnew vs. old

Back in the old days with DOS, PC-MATLAB, AT-MATLAB, 386 MATLAB and early versions for Windows (MATLAB 4, MATLAB 5, etc.) nobody could care less whether the .m extension is UPPER CASE or lower case. Versions after 2010 (or so) do. Anybody have a clue how to "rename" over 6500 m-files in one easy swoop?
C:\> rename *.M *.m doesn't seem to work to well in the Windows "DOS" prompt. 🙂
Case sensitive variables are great. Case sensitive m-files? Not so much. Picky, picky, picky.
Thanks.

Best Answer

You can use one of the many recursive dir() versions from the FileExchange, perhaps FEX:15859-subdir--a-recursive-file-search:
FileList = subdir('C:\YourBasePath\*.M');
for iFile = 1:numel(FileList)
newName = [FileList{iFile}(1:end-2), '.m'];
movefile(FileList{iFile}, newName);
end
But there are smarter tools for doing this directly, e.g. BulkRename or AF5 Rename your files. (Note: Bother tools can be downloaded free of charge for personal use, but there are professional licenses also.)
[EDITED] Thanks Guillaume:
Since Matlab R2016b and an alternative using fileparts:
FileList = dir('C:\YourBasePath\**\*.M');
for iFile = 1:numel(FileList)
folder = FileList{iFile}.folder;
name_ext = FileList{iFile}.name;
oldFile = fullfile(folder, name_ext);
[dummy, name] = fileparts(name_ext);
newFile = fullfile(folder, [name, '.m']);
movefile(oldFile, newFile);
end
Hm. A leaner version:
FileList = dir('C:\YourBasePath\**\*.M');
FileName = fullfile({FileList.folder}, {FileList.name});
for iFile = 1:numel(FileName)
newName = [FileName{iFile}(1:end-2), '.m'];
movefile(FileName{iFile}, newName);
end