I figured it out. The error was that the folder var needed a full path...
import os folder = "/home/zoli/PycharmProjects/leadingZeros/Scott.Ross_Goldberg.Variations/" os.chdir(folder) for i in os.listdir(folder): filename, extension = (os.path.splitext(i)) filenumber = (filename.split('.')[0].zfill(2)) filename = (filename.split('.')[1]) new_filename =('{}.{}{}'.format(filenumber, filename, extension)) #print(new_filename) os.rename(i, new_filename)Thanks for your help, I really needed to change into that directory. What I don't understund is, that if the script was able to change into that dir, and print the corrected filenames, why it needed an absolute path for the renaming.