python小程序-当前路径获取以及时间格式的文件夹创建

import os
from datetime import datetime

os.path.dirname(__file__)
print(os.path.abspath(__file__))
print(os.path.dirname(os.path.abspath(__file__)))
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# 当前时间,年月日
a = datetime.now().strftime("%Y%m%d%X")
b = datetime.now().strftime("%Y%m%d%H%M%S")
day = datetime.now().strftime("%Y%m%d")
print(a,b)
file_path ="{}\{}".format(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),day)

if os.path.exists(day):
    pass
else:
    os.mkdir(day)

 

posted @ 2022-03-11 14:11  依羽杉  阅读(139)  评论(0)    收藏  举报