Always Get Better

Never stop looking for ways to improve

January 1st, 2009

I needed to learn how to create directories using Python and found this great resource (digression: check out this author’s page headers – way cool!)

Although I didn’t really add anything new to the code, I ended up creating the following commented function which I share here in case it helps more users to understand.

# If directory (path) doesn’t exist, create it
def createPath(path):
if not os.path.isdir(path):
os.mkdir(path)

# Example of Windows file path
createPath( “C:\\Python\\myNewDirectory” )

# Example of Linux file path
createPath( “/home/username/myNewDirectory” )

No related posts.

  • Mike Wilson (160)
  • One Response to “ Create Directory in Python ”

    1. [...] Always Get Better Never stop looking for ways to improve « Create Directory in Python [...]

    Leave a Reply