问题
Below is my code to batch rename pictures inside a given directory
def multi_filename_change():
i = 0
files = askstring('Select your folder', 'Paste your directory path where your images are stored.')
for file in os.listdir(files):
if not file.startswith('.'):
file_name = askstring('Add file name', 'Please enter a name for your files.')
src = file
dst = file_name + str(i) + ".jpg"
os.rename(src, dst)
i += 1
When this is run I get the below error message:
os.rename(src, dst) FileNotFoundError: [Errno 2] No such file or directory: '360007_space-wallpaper-4k.jpg' -> 'test0.jpg'
I cannot seem to solve this and its probably an easy one for you experts :)
Thanks
回答1:
Source should be appended with existing directory, not just filename
src =files+file
Or
src=os.path.join(files, file)
来源:https://stackoverflow.com/questions/60577584/batch-file-rename-with-python