Batch File suffix modification:
Usage: s_rename (path, original suffix, new suffix)
# Coding: GBK # code by neeao # import OS, string def s_rename (path, old_ext, new_ext): For (path, dirs, files) in OS. walk (PATH): For filename in files: ext = OS. path. splitext (filename) [1] If (CMP (EXT, old_ext) = 0): newname = filename. replace (old_ext, new_ext) oldpath = path + "\" + filename newpath = path + "\" + newname print "oldpath:" + oldpath + "" print "newpth: "+ newpath +" try: OS. rename (oldpath, newpath) E Xcept valueerror: Print "error when rename the file" + oldpath failed t nameerror: Print "error when rename the file" + oldpath failed t oserror: # print oserror print newpath + "the file is already exist! "If _ name _ = '_ main _': s_rename (" F: \ code ",". ph ",". PL ") # print" test"
This article from: hacker Wu Lin (www.hack50.com) detailed source reference: http://www.hack50.com/stu/sort094/sort0108/18715.html