I need rename some files in dir after processing some regex on there files names and files types. I was looking for terminal / cmd command for this. Put I just wrote python script in few minutes (2 mins) and it works. It make my life easy with my PC.
In the directory there are huge amount of files with name that contains (some text).doc
eg:
Jane goes - (year 2010).mp3–> mydoc.mp3
02. feel like home- (uni).m–> 02. feel like home.mp3
python Code
import os
import re
files = os.listdir('.')
for file in files:
str = ''+file
new_name = re.sub(' - (.*).mp3$', '.mp3',str)
os.renames(file,new_name);
Add a comment