Creating a new Folder with given path

Victor Aguilar picture Victor Aguilar · Mar 15, 2017 · Viewed 24k times · Source

I'm wondering if any of you have created a function to create a folder within a given path.

For Example: NewFolder = ['/projects/Resources/backup_Folder']

Answer

Adam Hughes picture Adam Hughes · Mar 15, 2017

Use the os library, specifically os.mkdir()

https://docs.python.org/2/library/os.html#os.mkdir

For example,

path = "/usr/temp/foo"
os.mkdir(path)

If the intermediate folders don't exists, use os.makedirs as per Peter Wood's comment

path = "/newfolder1/newfolder2/foo"
os.mkdir(path)