创建目录

版权声明:转载请标明出处 https://blog.csdn.net/hanli1992/article/details/84863782
def mkdir(path):
    import os

#去除首位空格
path=path.strip()
#去除尾部'\'符号
path = path.rstrip('\\')

if not os.path.exists(path):    #判断目录是否存在
    os.makedirs(path)    #多层创建目录
    return True
else:
    print (path+'创建目录失败')
    return False

mkpath = 'd:\\test'
mkdir(mkpath)

猜你喜欢

转载自blog.csdn.net/hanli1992/article/details/84863782