python 脚本 自动创建年月日目录

本文介绍了一个Python脚本,该脚本可以根据指定年份创建包含所有日期的文件夹。脚本考虑了不同月份的天数差异及闰年情况。通过解析命令行参数来确定目标年份,并为每个月的每一天创建相应的目录。
import sys,os
def year(y):
f=0;
y=int(y)
if  y%4==0 and y%100!=0 :
f=1;
if y%400==0:
f=1;
return f
def mkdir():
y=sys.argv[1]
a=''
for i in range(1,13):
if i==1 or i==3 or i==5 or i==7 or i==8 or i==10 or i==12:
for j in range(1,32):
if i<10 and j<10 :
a=y+'0'+str(i)+'0'+str(j)
if i<10 and j>9 :
a=y+'0'+str(i)+str(j)
if i>9 and j<10:
a=y+str(i)+'0'+str(j)
if i>9 and j>9:
a=y+str(i)+str(j)
os.mkdir(a)
elif i==2:
if year(y):
for j in range(1,29):
if j<10:
a=y+'0'+str(i)+'0'+str(j)
if j>9:
a=y+'0'+str(i)+str(j)
os.mkdir(a)
else:
for j in range(1,30):
if j<10:
a=y+'0'+str(i)+'0'+str(j)
if j>9:
a=y+'0'+str(i)+str(j)
os.mkdir(a)
else:
for j in range(1,31):
if i<10 and j<10:
                a=y+'0'+str(i)+'0'+str(j)
                if i<10 and j>9 :
                    a=y+'0'+str(i)+str(j)
                if i>9 and j<10:
                a=y+str(i)+'0'+str(j)
                if i>9 and j>9:
a=y+str(i)+str(j)
os.mkdir(a)
mkdir()
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值