How to create new folder? [duplicate] How to create new folder? [duplicate] python python

How to create new folder? [duplicate]


You can create a folder with os.makedirs()
and use os.path.exists() to see if it already exists:

newpath = r'C:\Program Files\arbitrary' if not os.path.exists(newpath):    os.makedirs(newpath)

If you're trying to make an installer: Windows Installer does a lot of work for you.


Have you tried os.mkdir?

You might also try this little code snippet:

mypath = ...if not os.path.isdir(mypath):   os.makedirs(mypath)

makedirs creates multiple levels of directories, if needed.


You probably want os.makedirs as it will create intermediate directories as well, if needed.

import os#dir is not keyworddef makemydir(whatever):  try:    os.makedirs(whatever)  except OSError:    pass  # let exception propagate if we just can't  # cd into the specified directory  os.chdir(whatever)