如何在Python中创建多个嵌套文件夹? [英] How to create multiple nested folders in Python?
本文介绍了如何在Python中创建多个嵌套文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个根文件夹,例如Z.
I have a root folder, say Z.
在Z内部,我必须创建十个文件夹(例如Q,W,E,R,T,Y,U,I,O,P,A).此外,我想在这十个文件夹的每个中创建两个文件夹(例如M和N)
Inside Z, I have to create ten folders (say Q, W, E, R, T, Y, U, I, O, P, A). Further, I would like to make two folders (say M and N) in each of these ten folders
如何使用Python解决此问题?
How can I solve this using Python ?
推荐答案
import os
atuple = ('Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A')
atuple2 = ('M', 'N')
for dir1 in atuple:
for dir2 in atuple2:
os.makedirs(os.path.join(dir1, dir2))
这篇关于如何在Python中创建多个嵌套文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文