From ace808977608810a4b32cb1c9e804aaf9cbfd647 Mon Sep 17 00:00:00 2001 From: huangge1199 Date: Wed, 7 Aug 2024 17:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renamePhotoBatch.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/renamePhotoBatch.py b/renamePhotoBatch.py index 64df7e0..860f797 100644 --- a/renamePhotoBatch.py +++ b/renamePhotoBatch.py @@ -36,10 +36,15 @@ def solution(): # 遍历照片文件并重命名 for photo in photo_files: - creation_time_stamp = get_photo_taken_time(folder_path+"\\"+photo) + name = photo + photo = folder_path+"\\"+photo + creation_time_stamp = get_photo_taken_time(photo) if creation_time_stamp is None: continue - if photo.startswith('IMG'): + if name.startswith('IMG'): + file_name, file_ext = os.path.splitext(photo) + file_name = file_name[:-2] + os.rename(photo, f"{file_name}.jpeg") continue formatted_time = "IMG_" + creation_time_stamp.values.replace(':', '').replace(' ', '_') file_name, file_ext = os.path.splitext(photo) @@ -51,6 +56,7 @@ def solution(): while os.path.exists(new_file_path): new_file_name = f"{formatted_time}-{index}{file_ext}" new_file_path = os.path.join(folder_path, new_file_name) + index = index+1 os.rename(photo, new_file_path) print("照片重命名完成!")