Created
February 1, 2023 07:30
-
-
Save VinACE/2874565c9906d87980904ee8039005f5 to your computer and use it in GitHub Desktop.
Rename_files from 1 to N
This file contains hidden or 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 | |
path = '/path/to/folder' | |
# Get all the .png files in the folder | |
files = [file for file in os.listdir(path) if file.endswith('.png')] | |
# Sort the files | |
files.sort() | |
# Rename each file | |
for i, filename in enumerate(files): | |
os.rename(os.path.join(path, filename), os.path.join(path, str(i + 1) + '.png')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment