Created
July 16, 2023 23:17
-
-
Save Edwardtonnn/3078f7f1c6905895aa6d03d0917433b8 to your computer and use it in GitHub Desktop.
Renames jpg or png files to sequence 01.jpg and output jpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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