Batch rename sequential files by padding with zeroes

Python import os path=”/path/to/files/” for filename in os.listdir(path): prefix, num = filename[:-4].split(‘_’) num = num.zfill(4) new_filename = prefix + “_” + num + “.png” os.rename(os.path.join(path, filename), os.path.join(path, new_filename)) you could compile a list of valid filenames assuming that all files that start with “output_” and end with “.png” are valid files: l = [(x, “output” … Read more