import os r = os.path.dirname(__file__) b = 'task' os.mkdir(r+'/'+b) a = ['bin','db','lib','config','log'] for i in a: os.mkdir(r+'/'+b+'/'+i)
嵌套文件夹创建
import os r = os.path.dirname(__file__) a = 'Blank' Blank= os.mkdir(r + '/' + a ) b = ['Client','Manage','Server'] Client = ['config','lib',] Manage = ['config','lib',] Server = ['bin','config','db','log','lib',] for i in b: if i == b[0]: os.mkdir(r +'/'+ a + '/' + i) for i1 in Client: os.mkdir(r +'/'+a+'/'+i+'/'+i1) elif i == b[1]: os.mkdir(r +'/'+ a + '/' + i) for i1 in Manage: os.mkdir(r +'/'+a+'/'+i+'/'+i1) elif i ==b[2]: os.mkdir(r +'/'+ a + '/' + i) for i1 in Server: os.mkdir(r +'/'+a+'/'+i+'/'+i1)