Skip to content

Instantly share code, notes, and snippets.

@Edwardtonnn
Created July 16, 2023 23:17
Show Gist options
  • Save Edwardtonnn/3078f7f1c6905895aa6d03d0917433b8 to your computer and use it in GitHub Desktop.
Save Edwardtonnn/3078f7f1c6905895aa6d03d0917433b8 to your computer and use it in GitHub Desktop.
Renames jpg or png files to sequence 01.jpg and output jpg
import os
def rename_files(extension):
files = [f for f in os.listdir() if f.endswith(extension)]
for i, file in enumerate(sorted(files), start=1):
os.rename(file, f"{str(i).zfill(2)}{extension}")
if __name__ == "__main__":
rename_files(".jpg")
rename_files(".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment