# -*- coding: utf-8 -*-
import datetime
from pathlib import Path
def mk_ymd_dir(dir):
'''
创建年月日三级目录
dir: 父级目录
'''
x = datetime.datetime.now()
year = '{}'.format(x.year) # 年
month = '{}'.format(x.month) # 月
day = '{}'.format(x.day) # 日
# hour = '{}'.format(x.hour) # 时
# minute = '{}'.format(x.minute) # 分
# second = '{}'.format(x.second) # 秒
try:
cur_dir = Path(dir)
new_dir = cur_dir / year / month / day
if not new_dir.exists():
new_dir.mkdir(parents=True)
return True, '成功'
except Exception as e:
return False, '{}'.format(e)
if __name__ == "__main__":
is_success, tip = mk_ymd_dir('./')
print('{}:{}'.format(is_success, tip))
python创建年月日三级目录
最新推荐文章于 2025-02-27 17:30:23 发布
由于未提供博客具体内容,无法给出包含关键信息的摘要。
1689

被折叠的 条评论
为什么被折叠?



