12

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

1
  • what do you want exacly? and maybe you can have a look into the module os.path. Commented Mar 15, 2017 at 18:30

1 Answer 1

19

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)
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much Adam! It took me some time to understand what I was doing. I'm new to programming less than a year. landed an internship with a data science team. So this is all a learning experience for me. You were able to solve my issue.
Happy to help, good luck with your internship
This won't work if intermediate directories don't exist (e.g. if /usr/temp doesn't exist). You need os.makedirs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.