Skip to content

Instantly share code, notes, and snippets.

@VinACE
Created February 1, 2023 07:30
Show Gist options
  • Save VinACE/2874565c9906d87980904ee8039005f5 to your computer and use it in GitHub Desktop.
Save VinACE/2874565c9906d87980904ee8039005f5 to your computer and use it in GitHub Desktop.
Rename_files from 1 to N
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