适用于如何在src = Processing中创建所有文件夹的步骤。 但是我怎样才能创建 - 在每个刚创建的文件夹中的所有数据(文件,文件夹)在模板中。因此,在刚刚创建的文件夹中执行shutil.copytree。步行槽文件夹 - 复制主文件夹名称,而不是主文件夹中的文件和文件夹
src = "C:/code/CopyFolder/Processing" # must be the processing folder
dest = "C:/code/CopyFolder/Runs" # must be the runs folder
template = "C:/code/CopyFolder/Template" # source where to get Template files
print src
print dest
print template
listDirs = os.listdir(src)
print listDirs
for i in listDirs:
os.makedirs(dest + '/' + i) # should i do shutil.copytree() here for copy all files, folders from template in every just created folder?
print i + " " + "path is created"
#shutil.copytree(template, dest)
除了5个主目录之外,Processing中是否还有其他文件?如果没有,那么你可以创建一个文件夹名称列表和os.makedirs()他们都在一个循环。如果存在,只需使用os.path.isdir()剔除您的列表。 –
我更新了代码,但得到错误183:无法创建文件已经存在。我的路径写错了吗? –
这确实是不正确的。 os.path.dirname(src)只会给你'copyFolder',这显然已经存在于当前目录中。你想遍历目录列表并将dest连接到每个目录,然后makedir()生成的路径。 –