Created
September 6, 2016 01:11
-
-
Save nithesh1992/968b80c79d43e411e519fb58f9380258 to your computer and use it in GitHub Desktop.
renaming multiple files in python
This file contains 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
# 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