#coding=gbk
import os
import sys
def rename():
path = input("请输入路径(例如D:\\\\picture):")
name=input("请输入开头名:")
startNumber = input("请输入开始数:")
fileType = input("请输入后缀名(如 .jpg、.txt等等):")
filelsit=os.listdir(path)
print(filelsit)
count=0
for file in filelsit:
Olddir=os.path.join(path,file)
print(Olddir)
print(file[0:10])
if file[0:10]=="2021-09-03":
count=count+1
Newdir = os.path.join(path, name+str(count) + fileType)
os.rename(Olddir,Newdir)
print("一共修改了"+str(count)+"个文件")
rename()
这个代码是在上次上传的批量命名的改进,这里添加了筛选文件的条件。