Victor Aguilar
Victor Aguilar

Reputation: 139

Creating a new Folder with given path

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']

Upvotes: 12

Views: 27008

Answers (1)

Adam Hughes
Adam Hughes

Reputation: 16319

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)

Upvotes: 19

Related Questions