I would like to rename a 100 jpg images name at once

5 ビュー (過去 30 日間)
Vibha S
Vibha S 2023 年 1 月 10 日
編集済み: DGM 2023 年 1 月 10 日
My present jpg file names are of the form IMG1 01).jpg.jpg
IMG1 02).jpg.jpg
IMG1 03).jpg.jpg...
IMG1 10758).jpg.jpg.
Would like to change it to IMG_00001, IMG_00002..
Thanks in advance

回答 (2 件)

DGM
DGM 2023 年 1 月 10 日

Cameron
Cameron 2023 年 1 月 10 日
OldNames = "IMG1 " + transpose(string(1:10758)) + ").jpg.jpg";
OldNames(1:9,1) = "IMG1 0" + transpose(string(1:9)) + ").jpg.jpg";
mkdir NewFiles
for xx = 1:length(OldNames)
copyfile(OldNames(xx),'NewFiles');
end
cd('NewFiles')
for yy = 1:length(OldNames)
NewName = sprintf('%05d',yy);
movefile(OldNames(yy),NewName)
end
  4 件のコメント
Vibha S
Vibha S 2023 年 1 月 10 日
No it didnt transfer any file,
MY files areIMG1 01).jpg.jpg
DGM
DGM 2023 年 1 月 10 日
編集済み: DGM 2023 年 1 月 10 日
You have 100 files, but you haven't clearly described where they are or how they're named.
The above script assumes your images are in the current directory.
If you have 100 numbered images whose names contain an arbitrary subset of the numbers [1 10758], then you will have to know which ones you have and how that substring is zero-padded. Perhaps it's merely all the files in a particular directory?
Since this isn't the full set from 1 to 10758, it's also important to know whether the specific number in the filename should be reused, or whether it's sufficient to merely renumber the files sequentially.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by