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

来源:互联网 发布:淘宝卖家需要多少钱 编辑:程序博客网 时间:2024/05/16 08:13
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()
0 0
原创粉丝点击