步骤1:确定需要创建的文件夹
将需要创建的文件夹按行放置于txt文件中
例:list.txt
需要创建的文件夹1
需要创建的文件夹2
需要创建的文件夹3
步骤2:创建函数用于读取list.txt
def txtline2list(txtpath):
f = open(txtpath,'r', encoding='utf-8')
content = f.readlines()
conresult = [x.strip() for x in content]
return conresult
步骤3:创建函数用于创建文件夹
def mkdir(path):
# 引入模块
# 去除首位空格
path = path.strip()
# 去除尾部 \ 符号
path = path.rstrip("\\")
# 判断路径是否存在
# 存在 True
# 不存在 False
isExists = os.path.exists(path)
# 判断结果
if not isExists:
# 如果不存在则创建目录
os.makedirs(path)
print
path + ' 创建成功'
return True
else:
# 如果目录存在则不创建,并提示目录已存在
print
path + ' 目录已存在'
retur