创建文件夹

创建文件夹

# 创建文件夹
def mkdir(path):
    # 引入模块
    import os
    # 去除首位空格
    path = path.strip()
    # 去除尾部 \ 符号
    path = path.rstrip("\\")
    # 判断路径是否存在
    isExists = os.path.exists(path)
    if not isExists:
        os.makedirs(path)
        print(path + ' 创建成功')
        return True
    else:
        print(path + ' 目录已存在')
        return False

# 定义要创建的目录
mkpath = "D:\\雅诗兰黛\\tmp\\%s" % (sheet_m)
# 调用函数
mkdir(mkpath)
posted @ 2020-06-17 14:13  JIAYIYAN  阅读(200)  评论(0编辑  收藏  举报