存在问题:
1.多次重复运行会导致文件丢失
2.文件原有顺序会被打乱
import os
count = 1
path = ""
filelist = os.listdir(path)
for file in filelist:
print(file)
for file in filelist:
Olddir = os.path.join(path, file)
if os.path.isdir(Olddir):
continue
filename = os.path.splitext(file)[0]
filetype = os.path.splitext(file)[1]
Newdir = os.path.join(path, +str(count).zfill(4) + filetype)
os.rename(Olddir, Newdir)
count += 1