Effacer les filtres
Effacer les filtres

How to rename .m files

30 vues (au cours des 30 derniers jours)
Harish Patil
Harish Patil le 15 Juin 2015
Commenté : Walter Roberson le 13 Oct 2015
In my current directory bunch of XXX.mat files to be rename as XXXNewname.mat files using MATLAB command prompt . Anyone knows ????

Réponse acceptée

Walter Roberson
Walter Roberson le 15 Juin 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 commentaires
Harish Patil
Harish Patil le 13 Oct 2015
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 le 13 Oct 2015
folderinfo = folderinfo(~ismember({folderinfo.name}, {'.', '..'})); %remove directories . and ..
but adapt that for dinfo and the two names you want to leave alone

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by