Skip to content

Instantly share code, notes, and snippets.

@nithesh1992
Created September 6, 2016 01:11
Show Gist options
  • Save nithesh1992/968b80c79d43e411e519fb58f9380258 to your computer and use it in GitHub Desktop.
Save nithesh1992/968b80c79d43e411e519fb58f9380258 to your computer and use it in GitHub Desktop.
renaming multiple files in python
# reNamer - By Nithesh. Customize the Name part as you like to rename your bulk files in a directory
import os
os.chdir("D:/filerename")
i=0
for f in os.listdir():
name, ext = os.path.splitext(f)
i = i + 1
print(f)
hname, extra = name.split('_')
name = hname.strip()
ext = ext.strip()
new = '{}-{}{}'.format(name,i,ext)
os.rename(f, new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment