How can I safely create a directory (possibly including intermediate directories)?

asked17 years ago
last updated2 years ago
viewed3.5m times
Up Vote5.5kDown Vote

I am writing a file using Python, and I want it to be placed in a specific path. How can I safely make sure that the path exists? That is: how can I check whether the folder exists, along with its parents? If there are missing folders along the path, how can I create them?