1 import os 2 3 def renameFile(): 4 try: 5 os.rename(srcFile,dstFile) 6 except Exception as e: 7 print(e) 8 print('rename file fail\r\n' + srcFile ) 9 else: 10 print('rename file success\r\n' + dstFile ) 11 12 if __name__=="__main__": 13 srcFile = 'D:/111.xls' 14 dstFile = 'D:/222.xls' 15 renameFile()