/ Published in: Python
This code changes the part of the file name in accordance with the pattern
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/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)
URL: python_renamer