Python笔记-使用os和os.path进行目录操作

文章目录

介绍

os.path.exists('test')可判断目录test是否存在,存在则返回True,不存在返回False
os.mkdir('test')创建文件夹test

代码

import os
import os.path

#文件夹相应的路径,可填写相对路径或绝对路径。
path = 'test'

#若test文件夹不存在时,创建文件夹
if(os.path.exists(path)==False):
  os.mkdir(path)
原创文章 31 获赞 11 访问量 6120

猜你喜欢

转载自blog.csdn.net/smallfox233/article/details/105790621