How to rename .m files
71 ビュー (過去 30 日間)
古いコメントを表示
In my current directory bunch of XXX.mat files to be rename as XXXNewname.mat files using MATLAB command prompt . Anyone knows ????
0 件のコメント
採用された回答
Walter Roberson
2015 年 6 月 15 日
newstr = 'Newname';
dinfo = dir('*.mat');
for K = 1 : length(dinfo)
thisfile = dinfo(K).name;
[pathstr, base, ext] = fileparts(thisfile);
if strncmp( fliplr(base), fliplr(newstr), length(newstr) ) %compare ends
continue; %this one has already been renamed
end
newfid = fullfile(pathstr, [base newstr ext]);
movefile(thisfile, newfid);
end
3 件のコメント
Walter Roberson
2015 年 10 月 13 日
folderinfo = folderinfo(~ismember({folderinfo.name}, {'.', '..'})); %remove directories . and ..
but adapt that for dinfo and the two names you want to leave alone
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!