【发布时间】:2021-06-14 09:37:56
【问题描述】:
如何检查文件夹是否存在,如果不存在则创建它?
import os
from datetime import datetime
file_path = "F:/TEST--"
if os.path.exists(file_path):
os.rmdir(file_path)
os.makedirs(file_path + datetime.now().strftime('%Y-%m-%d'))
else:
os.makedirs(file_path + datetime.now().strftime('%Y-%m-%d'))
【问题讨论】:
-
你有什么问题?
-
如果已经存在则不创建文件夹