4

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
  • 17,184
  • 7
  • 46
  • 64
gowtham
  • 51
  • 2
  • 2
  • 4

2 Answers2

6

The following functions may help:

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
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,407
  • 1
  • 24
  • 32