需求说明:某文件夹下存有一批语音文件,文件命名无规则。需要将该文件夹下所有文件改成指定名字。
import os
import sys
path = r"E:\语音测试集\xiaozhi\女"
for (path, dirs, files) in os.walk(path):
i=0
for filename in files:
namesplist=filename.split(".")
format = str(namesplist[-1])
i=i+1
newname = "xiaozhi_woman_"+str(i)
os.rename(path + "\\" + filename, path + "\\" + newname + "." + format)