Change names of multiple pictures inside a file

1 vue (au cours des 30 derniers jours)
lena kappa
lena kappa le 20 Avr 2021
Commenté : lena kappa le 20 Avr 2021
Hi everyone, I have 25+ pics in a file named 1,2,3...up to lets say 25 and want to change their names to lets say cat1, cat2,...up to cat25
the next code does indeed change the names but not in the corect order because it reads the images in this way 1,10,11 bla bla 2,20 ... so the images get all messed up,how can i change the names in the corect way ?
a ='C:\Users\nas\Desktop\0.3';
A =dir( fullfile(a, '*.jpg') );
fileNames = { A.name };
for iFile = 1 : numel( A )
newName = fullfile(a, sprintf( '%05d.jpg', iFile ) );
movefile( fullfile(a, fileNames{ iFile }), newName );
end

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Avr 2021
a ='C:\Users\nas\Desktop\0.3';
A = dir( fullfile(a, '*.jpg') );
fileNames = fullfile({A.folder}, {A.name});
for iFile = 1 : numel(fileNames)
oldname = fileNames{iFile};
[fold, basename, ext] = fileparts(oldname);
newbase = regexprep(basename, '.*?(\d+)$', 'cat$1')
newName = fullfile(fold, [newbase ext]);
movefile( oldname, newName );
end
  1 commentaire
lena kappa
lena kappa le 20 Avr 2021
Thank you walter!!! have a nice day!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by