2016-12-24 87 views
1

我对此非常陌生,我本质上是试图创作一个剧本来处理故事片,这样每天我都可以为该特定拍摄日制作一组新的文件夹,以便我可以卸载文件。Python - 如何在新创建的目录中创建多个文件夹?

到目前为止,我已经能够使用用户输入制作的文件夹,然后将实际日期添加到该文件名中。

但是我卡住的地方是试图在这个新创建的文件夹中添加文件夹。

print ('') 
print '\033[4m' + "Hello, Please select a shoot day to begin - this only works up until 12pm" + '\033[0m' 
import os 
import sys 
import time, datetime 

today = datetime.date.today() # get today's date as a datetime type 

todaystr = today.isoformat() # get string representation: YYYY_MM_DD 
           # from a datetime type. 


print('') 
user_input = raw_input('\033[1m' + 'Enter Shoot Day Here -' + '\033[0m') 

path1 = user_input 
if not os.path.exists(path1): 
    os.makedirs(path1 +'_' + todaystr) 

所以这给我创建了一个名为015_2016-12-24的文件夹。然后,我希望能够在这些文件夹内添加多个文件夹。

只是在这里尽力而为对不起,如果这是一个愚蠢的问题。谢谢你的帮助 !

回答

2
os.makedirs(path1 +'_' + todaystr+'/'+name of subfolder) 

这将允许您为新创建的文件夹

+0

好了完美的创建子文件夹,我知道这将是一些简单。 但是,那么我怎么会一次添加多个文件夹呢? Lets说我想创建3个文件夹,称为'ari''声音'和'md5',并希望他们都在该顶部文件夹?只需加上 - 'os.makedirs(path1 +'_'+ todaystr +'/ ari'+'sound')' 只是让文件夹名称'arisound'正确吗? –

+0

@JonathanPetts'在['ari ','sound','md5']:os.makedirs(path1 +'_'+ todaystr + name)'这将创建三个子文件夹。 –

相关问题