Python操作文件技巧(二)
作者:互联网
1. 文件重命名为3位数 (0补齐)
import os
path =r'C:\Users\Administrator\Desktop\file'
for file in os.listdir(path):
name = file.split('.')[0]
yuan = os.path.join(path, file)
xin = os.path.join(path, '%03d' % int(name) + ".jpg")
os.rename(yuan,xin) # %03d 表示一共3位数
标签:文件,技巧,Python,xin,03d,file,path,yuan,os 来源: https://blog.csdn.net/qq_41939362/article/details/113763365