Skip to content

Instantly share code, notes, and snippets.

@Trimad
Created November 13, 2022 02:19
Show Gist options
  • Save Trimad/9c4eb5c35176912e0c8fc354c82d2fd2 to your computer and use it in GitHub Desktop.
Save Trimad/9c4eb5c35176912e0c8fc354c82d2fd2 to your computer and use it in GitHub Desktop.
Renames a folder of .png files to be sequential with leading zeros.
import os
import pathlib
collection = os.getcwd()
#print(collection)
for i, filename in enumerate(os.listdir(collection)):
file_extension = pathlib.Path(filename).suffix
#print("File Extension: ", file_extension)
if(file_extension == ".png"):
os.rename(collection +"\\"+ filename, collection +"\\"+ str(i).zfill(4) + ".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment