PS:本文主要用于自我整理总结,方便后续参考,如果恰好帮助到你,也是件值得高兴的事
根据年月日时分秒的时间命名并创建文件夹
import os
from datetime import datetime
now = datetime.now() # 获得当前时间
timestr = now.strftime("%Y_%m_%d_%H_%M_%S")
print('年_月_日_时_分_秒:', timestr)
dir = os.getcwd() + '/演示' + timestr # os.getcwd()获得当前执行目录
if os.path.exists(dir): # 看文件夹是否存在
print('文件夹已存在')
else: # 如果不存在
os.makedirs(dir) # 则创建文件夹
创建出的新文件夹: