How to rename .m files
69 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Harish Patil
am 15 Jun. 2015
Kommentiert: Walter Roberson
am 13 Okt. 2015
In my current directory bunch of XXX.mat files to be rename as XXXNewname.mat files using MATLAB command prompt . Anyone knows ????
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 15 Jun. 2015
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 Kommentare
Walter Roberson
am 13 Okt. 2015
folderinfo = folderinfo(~ismember({folderinfo.name}, {'.', '..'})); %remove directories . and ..
but adapt that for dinfo and the two names you want to leave alone
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!