In [16]:
import os
import sys
import shutil
In [17]:
def rename_all_files(CWD,sign):
#CWD -current working dir
#rename all files
#if dir then go in & rename all sub-files
files=list(os.listdir(CWD))
os.chdir(CWD)
#start renaming recursively
for fle in files:
if not os.path.isdir(fle):
if fle.find(sign) == -1:
ls=fle.split(".")
new_name=".".join(ls[:-1])+"- "+sign+"."+ls[-1]
os.rename(fle,new_name)
else:
rename_all_files(os.path.join(CWD,fle),sign)
return os.chdir("..")
In [25]:
print "location format windows E:\\temp \n"
#base_dir="E:\\temp"
base_dir = raw_input('Enter base file location:')
sign='[Codecops.in]'
#sign =raw_input("Enter your sign : ")
In [26]:
#move to base directory
print os.getcwd()
os.chdir(base_dir)
print os.getcwd()
In [27]:
## __main__
print 'Base address is :',os.getcwd()
check_point=raw_input("R you sure to perform operation[y/n] : ")
if check_point=='y' or check_point =='Y':
rename_all_files(os.getcwd(),sign)
print "Done Thank You"
else:
print "Ok Bye"
exit()
In [21]:
os.getcwd()
Out[21]: