我正在尝试批量重命名一些照片,我只想要第二部分,例如重命名 from 1234 - Photo_Name.jpg
to Photo_Name.jpg
。
这是我的代码:
import os
folder = r"C:\Users\yousef\Downloads\Pictures\\"
files = os.listdir(folder)
for file_name in files:
new_filename = file_name.split(' - ')[1]
os.rename(file_name, new_filename)
但我得到这个错误
File "c:\Users\yousef\Downloads\code.py", line 7, in <module>
os.rename(file_name, new_filename)
FileNotFoundError: [WinError 2] The system cannot find the file specified: '1234 - Photo_Name.jpg' -> 'Photo_Name.jpg'