大量文件名需要進行有序整理時,可以使用Python的OS模塊進行文件批量重命名,腳本如下:
import os path = 'D:\PycharmProjects\download_photos\down_photos' #文件路徑 count = 1 filelist = os.listdir(path) #該文件夾下所有文件 def rename(): global count for files in filelist: #遍歷文件 Olddir = os.path.join(path,files) #原來的文件路徑 filename = os.path.splitext(files)[0] #文件名 filetype = os.path.splitext(files)[1] #文件擴展名 #print(filename) #print(filetype) Newdir = os.path.join(path,"文件名"+str(count)+".jpg") #新的文件路徑 os.rename(Olddir,Newdir) #重命名 count+=1 rename()