MATLAB Versions 1 through 13
조회 수: 7 (최근 30일)
이전 댓글 표시
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.
댓글 수: 3
Jan
2017년 2월 28일
What exactly does "doesn't seem to work well" mean? The command works well and I hesitate now to suggest it again, but I cannot guess, what's the problem.
채택된 답변
Jan
2017년 2월 28일
편집: Jan
2017년 2월 28일
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
댓글 수: 3
Walter Roberson
2017년 2월 28일
If you are using MS Windows with FAT* then I gather that it is not possible to turn off case *in*sensitivity at the file system level. If you are using MS Windows with NTFS then I gather that it is possible to turn off case *in*sensitivity at the file system level, but not often done.
When case *in*sensitivity is on at the filesystem level, then if you attempt to movefile() a file to a name that is the same but a different case combination, then movefile() will consider the source and destination to be the same and will leave them unchanged. Therefore on such systems, you need to movefile() to a name that is not a case insensitive match for any existing file, and the movefile() to the desired name.
You might want to use tempname() to pick a temporary file name that is not in use.
Remember to use a bunch of try/catch and success tests in case one of the movefiles fails
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!