您当前的位置: 首页 >  Python

IT之一小佬

暂无认证

  • 2浏览

    0关注

    1192博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python创建目录文件夹

IT之一小佬 发布时间:2021-02-05 15:47:18 ,浏览量:2

Python创建目录文件夹

Python对文件的操作还算是方便的,只需要包含os模块进来,使用相关函数即可实现目录的创建。

主要涉及到三个函数

1、os.path.exists(path) 判断一个目录是否存在

2、os.makedirs(path) 多层创建目录

3、os.mkdir(path) 创建目录

示例代码1(创建目录):

dir_name = './download'
if not os.path.exists(dir_name):     # 创建文件夹
    os.mkdir(dir_name)

示例代码2(多层创建目录):

dir_name = './download/images'
if not os.path.exists(dir_name):     # 创建文件夹
    os.makedirs(dir_name)

 

关注
打赏
1665675218
查看更多评论
立即登录/注册

微信扫码登录

0.0471s