Batch File Rename with Python

BIGPESH :

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

Ajay Tom George :

Source should be appended with existing directory, not just filename

src =files+file

Or
src=os.path.join(files, file)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=33349&siteId=1