How to rename .m files

15 次查看(过去 30 天)
In my current directory bunch of XXX.mat files to be rename as XXXNewname.mat files using MATLAB command prompt . Anyone knows ????

采纳的回答

Walter Roberson
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 个评论
Harish Patil
Harish Patil 2015-10-13
Hi Walter Roberson , I have a another doubt : Except 2 files in my directory I need to rename all files.... can you please help the same.
Walter Roberson
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 CenterFile Exchange 中查找有关 Search Path 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by