Skip to content

Instantly share code, notes, and snippets.

@konverner
Last active October 16, 2022 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konverner/da356890ef1d8f1ac6419d307403e504 to your computer and use it in GitHub Desktop.
Save konverner/da356890ef1d8f1ac6419d307403e504 to your computer and use it in GitHub Desktop.
Rename batch of files in Windows directory with Python
import os
# here a path to a folder with files
PATH = r'C:\folder_to_rename'
# Filename extension
extension = '.png'
# in this case it numerates files from 0 to N, where N is a number of files.
i = 0
for filename in os.listdir(PATH):
os.rename(PATH+'\\'+filename,PATH+'\\'+str(i)+extension)
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment