Determining Whether a Directory is Writeable

illuminatedtiger picture illuminatedtiger · Jan 21, 2010 · Viewed 71.5k times · Source

What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment.

Answer

Max Shawabkeh picture Max Shawabkeh · Jan 21, 2010

Although what Christophe suggested is a more Pythonic solution, the os module does have the os.access function to check access:

os.access('/path/to/folder', os.W_OK) # W_OK is for writing, R_OK for reading, etc.