# 批量修改当前文件下所有文件名
import os
path = "d:/test"
files = os.listdir(path)
# print(os.listdir(path)) ['123.txt', '456.txt', '789.txt']
order = 1
for file in files:
old = path + os.sep + file # d:/test/1.txt
new = path + os.sep + "a" + str(order) + ".txt" # d:/test/a1.txt
os.rename(old, new)
order += 1
python 批量修改文件名称
最新推荐文章于 2024-11-13 17:26:18 发布