按日期批量创建文件夹

import os,random
path=r"D:\pylx\20210622"
for i in range(20):
ym = '202106'
d = random.randint(10, 22)
dd = str(d)
rand_num = str(random.randint(0, 9999999))
new_number = rand_num.zfill(4)
folder = ym + dd + new_number
file_name = path + "\\" + folder+".file"
isExists=os.path.exists(file_name)
if not isExists:
os.makedirs(file_name)
print('%s 创建文件夹成功'%file_name)
else:
print('%s 文件夹名称已存在'%file_name)
continue
posted @ 2021-06-22 14:15  小蕊-zr  阅读(1216)  评论(0编辑  收藏  举报