指定內容批量新建目錄

 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文件,裏面分行輸入目錄名字就行this

相關文章
相關標籤/搜索