check whether directory is readable

E

eels

Hello,
how can I check whether a directory is readable or not. Are there
differences between unix and windows?
Thank you for your hints, Eels
 
B

Ben Finney

eels said:
how can I check whether a directory is readable or not. Are there
differences between unix and windows?

The Pythonic way would be to just do what you need to do (in this
case, presumably, read the directory) and catch the specific exception
(in this case, presumably, OSError).

try:
# Do whatever needs a readable directory
normal_reading_stuff()

except OSError, e:
# Do whatever we need to when the directory is unreadable
print "Unable to read stuff:", e.strerror
 
J

Jonas Geiregat

eels said:
Hello,
how can I check whether a directory is readable or not. Are there
differences between unix and windows?

As far as I know there aren't any differences,

code:

import os
if access("/root", os.R_OK):
print "You are able to read the /root dir"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top