3

I want to create a path like C:\sample\sample1\hello.py. It should automatically create the complete path from sample to hello.py, and all the directories in between. Is this possible in Python?

Amit Kumar Gupta
  • 15,516
  • 6
  • 43
  • 60
gowtham
  • 167
  • 1
  • 2
  • 4

2 Answers2

6

The following functions may help:

Sjoerd
  • 71,634
  • 16
  • 123
  • 171
2
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))
TarasB
  • 2,289
  • 1
  • 23
  • 31