python3批量為文件重命名

簡介

為什麼使用python批量重命名而沒有使用shell,python對文字的處理更靈活,對於文件名中的空格不會出現報錯。

程式碼:

#!/usr/bin/env python  # -*- coding:utf-8 -*-  """  @author:Aiker Zhao  @file:rename_all.py  @time:下午10:29  """    import os    path = "M:\bd1\都挺好\"  new_path = "M:\bd1\doutinghao\"  for file in os.listdir(path):      # print(file)      if os.path.isfile(os.path.join(path, file)) == True:          if file.find('.mp4') < 0:              print(file)          else:              file_number = file.split('@')[0]              print(file_number)              new_file_name = '都挺好' + file_number + '.mp4'              print(new_file_name)              os.rename(os.path.join(path, file), os.path.join(new_path, new_file_name))

對於不規範的文件重命名,可以使用excel表格,通過對表格的處理來重命名,