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("照片重命名完成!")