Rename many images using loop function and movefile function

9 vues (au cours des 30 derniers jours)
Eric
Eric le 21 Mai 2011
Commenté : Zara Khan le 6 Juil 2022
Greeting. Sorry for my ignorance in computer science. I am new in digital image processing. I face problems in rename-ing 20 images. Here is my code:
a ='C:\Users\Ace\Desktop\rename\';
A =dir( strcat (a, '*.bmp' ));
fileNames = { A.name };
for iFile = 1 : numel( A )
newName = sprintf( '%05d.bmp', iFile );
movefile( fileNames{ iFile }, newName );
end
Error message came out: " ??? Error using ==> movefile No matching files were found. "
And I notice the "movefile( fileNames{ iFile }, newName ); " does not run.
Any expert can offer me guidance how to rename file using movefile function? Or I have missed a step or made syntax error?
Thanks.

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Mai 2011
The name field returned by dir() does not include the directory.
a ='C:\Users\Ace\Desktop\rename\';
A =dir( fullfile(a, '*.bmp') );
fileNames = { A.name };
for iFile = 1 : numel( A )
newName = fullfile(a, sprintf( '%05d.bmp', iFile ) );
movefile( fullfile(a, fileNames{ iFile }), newName );
end
  7 commentaires
Mahtab Mohammadpoor faskhodi
I used this order but I found a problem, my files do not rename in an order. It means that they mixed up. what should I do to make them in the same order that they hade before rename.
Zara Khan
Zara Khan le 6 Juil 2022
Walter Roberson : working but not happening in original order. Please check

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations 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