1、新建文件夹名称列表文件folders.txt,如下图:(文件夹名称用逗号隔开)
2、源代码如下:(该代码自动创建二级文件夹,大家可以根据需要灵活修改)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 批量新建文件夹
import os
filename="folders.txt"
with open(filename,"r",encoding="utf-8") as f:
for fd in f.readlines():
folder = fd.split(",")
path = "{}/{}".format(folder[0],folder[1].strip())
print(path)
os.makedirs(path)