在python中自动创建多个文件夹

在python中自动创建多个文件夹,python,file,creation,Python,File,Creation,我想创建一个路径,如C:\sample\sample1\hello.py。它应该自动创建从sample到hello.py的完整路径,以及其间的所有目录。这在Python中可能吗?以下函数可能会有所帮助: import os root_path = 'C:\path' folders = ['folder 01', 'folder 02', 'folder 03'] for folder in folders: os.mkdir(os.path.join(root_path

我想创建一个路径,如
C:\sample\sample1\hello.py
。它应该自动创建从
sample
hello.py
的完整路径,以及其间的所有目录。这在Python中可能吗?

以下函数可能会有所帮助:

import os
root_path = 'C:\path'

folders = ['folder 01', 'folder 02', 'folder 03']

for folder in folders:

    os.mkdir(os.path.join(root_path, folder))