In the os
module in Python, is there a way to find if a directory exists, something like:
>>> os.direxists(os.path.join(os.getcwd()), 'new_folder')) # in pseudocode
True/False
You're looking for Example:
|
|||||||||
|
Yes, use |
|||||||||
|
So close! |
|||
|
Yes use os.path.isdir(path) |
|||
|
As in:
Probably toss in a |
|||
|
os provides you with a lot of these capabilities:
the listdir will throw an exception if the input path is invalid. |
||||
|
Just to provide the
|
||||
|
os.stat
instead, to see if the directory both exists and is a directory at the same moment. – d33tah Feb 11 '14 at 17:09os.stat
to tell directory from a file. It raisesOSError
when the path is invalid, no matter whether it's file or directory. Also, any code after checking is also susceptible to race conditions. – Tomáš Zato Sep 7 '15 at 14:58