import os
import os.path
folderPath = r"D:\test"
i = 0
for file in os.listdir(folderPath):
print("{1:4d} is {0!s} ".format(file, i)) # 学习format
if os.path.isfile(os.path.join(folderPath, file))==True:
if file.find('.')>=0:
newName = str(i) + "_" + file
print(newName)
os.rename(os.path.join(folderPath, file), os.path.join(folderPath, newName))
i+=1
# os.path.join('/hello/','good/boy/','doiido')
## '/hello/good/boy/doiido'
python 批量改变文件名
最新推荐文章于 2022-10-03 22:59:35 发布