python 检测文件目录是否存在 不存在就创建 检测文件是否存在 不存在就创建 linux

file_path="./log_record/"
if not os.path.exists(file_path):
    os.makedirs(file_path)
file_name=file_path+'log.log'
if not os.path.exists(file_name):
    os.system(r"touch {}".format(file_name))  # 调用系统命令行来创建文件

猜你喜欢

转载自blog.csdn.net/x1131230123/article/details/113247781