• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
宋宋974509823
博客园    首页    新随笔    联系   管理    订阅  订阅

指定内容批量新建目录

 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文件,里面分行输入目录名字就行

posted @ 2019-06-11 18:06  宋宋974509823  阅读(168)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3