Skip to content

Instantly share code, notes, and snippets.

@Edwardtonnn
Created July 13, 2023 21:01
Show Gist options
  • Save Edwardtonnn/b10c978314507f8d842dea7f51099b13 to your computer and use it in GitHub Desktop.
Save Edwardtonnn/b10c978314507f8d842dea7f51099b13 to your computer and use it in GitHub Desktop.
Rename Png images to sequence
import os
def rename_images():
image_files = [f for f in os.listdir() if f.endswith('.png')]
image_files.sort()
for i, filename in enumerate(image_files):
new_filename = '{:02d}.png'.format(i + 1)
os.rename(filename, new_filename)
print('Renamed {} to {}'.format(filename, new_filename))
rename_images()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment