1 import os
2 def mkdir(path):
3 folder=os.path.exists(path)
4 if not folder:
5 os.makedirs(path)
6 print(path+"---OK---")
7 else:
8 print(path+"---There is this folder!---")
9
10 if __name__=='__main__':
11
12 with open('D:\input.txt','r') as f:
13 lines=f.readlines()
14 for line in lines:
15 folder=line
16 #strip()方法移除字符串头尾指定的字符
17 folder=folder.strip()
18 #print (folder)
19 mkdir(folder)
在D盘根目录新建一个input.txt文件,里面分行输入目录名字就行