How to rename .m files
59 次查看(过去 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!