将正确的文件名存在一个列表里,格式如下,文件名为filename.py
real_name = [
'0001 Introducing Yourself',
'0002 Getting Up',
'0003 Cleaning Up',
'0004 Eating Breakfast',
'0005 Getting Dressed & Ready for Work',
'0006 The Commute to Work',
'0007 At My Desk, on Break, and at Lunch',
'0008 The Commute Home and Running Errands',
'0009 Making Dinner, Eating Dinner',
'0010 Relaxing, Reading the Mail, and the Trash',
'0011 Getting Ready for Bed and Going to Sleep',
'0012 Small Talk About the Weather',
]
批量重命名
import os
import filename # 引入正确的文件名列表
path = 'E:/PDF' # 需要重命名文件夹路径
file_names = os.listdir(path)
i = 0
for name in file_names:
old_name = path +'/'+ file_names[i] # 读取单个文件现有名字
new_name = path + '/' + filename.real_name[i] + '.pdf' # 新名字
# newname = new_name[:-4] + '.mp3' #如果要替换文件扩展名则用这行
os.rename(old_name,new_name) #重命名
i += 1