Return to Snippet

Revision: 21325
at December 10, 2009 12:34 by iscarface


Initial Code
#!/usr/bin/python

import os, sys




def migrate(old_name, new_name, dir_name): 
        renamed=0
        notrenamed=0
        for walk in os.walk(dir_name): 
                filelist=walk[2]
                if filelist: 
                        for file in filelist:
                                oldfilename=walk[0]+file
                                newfilename=oldfilename.replace(old_name, new_name)
                                #os.rename(oldfilename, newfilename)
                                print "OLD_WAS: ", oldfilename
                                print "NEW_IS: ", newfilename
                                print 200*"-"

if __name__=="__main__": 
        if len(sys.argv)<4: 
                print "Error"
                sys.exit()
        old=sys.argv[1]
        new=sys.argv[2]
        dirname=sys.argv[3]
        if dirname[-1]!="/": 
                dirname=dirname+"/"
        migrate(old, new, dirname)

Initial URL
python_renamer

Initial Description
This code changes the part of the file name in accordance with the pattern

Initial Title
Filename changer

Initial Tags

                                

Initial Language
Python