【Python】【常用逻辑】检查文件夹是否存在

【背景】

经常用到的常用逻辑,判断文件夹是否存在,如果不存在则创

【代码】

if not os.path.exists(cur_path):
    os.mkdir(cur_path)

【解析】

这里,cur_path是指需要检查的文件夹路径,mkdir则是os模块自带的新建文件夹方法。

猜你喜欢

转载自blog.csdn.net/weixin_41697242/article/details/125524777