I have a script for renaming files, but can not seem to iron out the bugs.
I am trying to rename a list of files:
File1.File1
File2.File2
etc
I need them to be renamed to:
File1
File2
etc
This is the code so far:
import os
import sys
import time
def renamer(target) :
os.chdir(target)
for filename in os.listdir('.') :
print filename
i = filename.split(".")
if len(i) == 2 and i[-1] == i[-2]:
new_filename = i[1]
os.rename(filename, new_filename)
print "Renamed " + filename + " to " + new_filename
def main() :
renamer(sys.argv[1])
main()
I would like to improve on this, by adding in the ability to copy one last file, and rename it so that:
Copyme
becomes:
NewCopyme
any help would be much appreciated.
Thanks