Python|创建多级目录(文件夹)
Python 代码, 创建文件夹,支持多级目录。
def makeDirs(dirpath):
'''
创建目录
支持多级目录,若目录已存在自动忽略
Updated: 2020-05-12
GitHub: https://github.com/NodeWee/OpenSnippets/tree/master/Python
'''
import os
# 去除首尾空白符和右侧的路径分隔符
dirpath = dirpath.strip().rstrip(os.path.sep)
if dirpath:
if not os.path.exists(dirpath): # 如果目录已存在, 则忽略,否则才创建
os.makedirs(dirpath)
➦ on GitHub
(正文结束。芝士就是力量!)