使用python在多个现有文件夹中创建新的文件夹 [英] Create new folders within multiple existing folders with python

查看:746
本文介绍了使用python在多个现有文件夹中创建新的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在多个现有文件夹中创建新文件夹的方法。例如我有文件夹a,b,c ..等,我想在每个这些现有的文件夹内创建一个新文件夹,并使用python脚本命名新的文件夹a1,b1,c1,..等。

I am looking for a way to create new folders within multiple existing folders. For example I have folders a,b,c.. etc and I want to create a new folder inside each of these existing folders and name the new folders a1,b1,c1,.. etc. using a python script.

推荐答案

尝试循环浏览您的文件夹列表,而不是传入列表。这不是最干净的方法,但你可以这样做:

Try looping through your list of folders rather than passing in the list. It is not the cleanest method out there but you can do something like:

parents = [p1, p2, p3]
childern = [c1, c2, c3]

for p in parents:
   for c in children:
      os.mkdir(os.path.join(p,c))

这篇关于使用python在多个现有文件夹中创建新的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆