Checking File permissions

Discussion in 'Python' started by Anoop, Jul 20, 2006.

  1. Anoop

    Anoop Guest

    Hi All

    Please tell me how to check the existence of a file and the read
    permission to the file using python script

    Thanks for ur inputs

    Anoop
     
    Anoop, Jul 20, 2006
    #1
    1. Advertising

  2. Anoop

    Avell Diroll Guest

    Anoop wrote:
    > Please tell me how to check the existence of a file and the read
    > permission to the file using python script


    You can check the os module (os.stat comes to mind).

    For an exemple you can have a look at :
    http://www.pixelbeat.org/talks/python/ls.py

    Regards,

    Avell
     
    Avell Diroll, Jul 20, 2006
    #2
    1. Advertising

  3. Anoop

    Tal Einat Guest

    Anoop wrote:
    > Hi All
    >
    > Please tell me how to check the existence of a file and the read
    > permission to the file using python script
    >
    > Thanks for ur inputs
    >
    > Anoop


    os.access(path, mode) does just this, check it out.

    Cross-platform-ness isn't a problem, the docs say it is available for
    Windows, Unix and Mac, and I've used it without a hitch on Win2k, WinXP
    and various Linux and Unix platforms.

    >>> help(os.access)

    Help on built-in function access in module nt:

    access(...)
    access(path, mode) -> 1 if granted, 0 otherwise

    Use the real uid/gid to test for access to a path. Note that most
    operations will use the effective uid/gid, therefore this routine
    can
    be used in a suid/sgid environment to test if the invoking user has
    the
    specified access to the path. The mode argument can be F_OK to
    test
    existence, or the inclusive-OR of R_OK, W_OK, and X_OK.
     
    Tal Einat, Jul 21, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Allen
    Replies:
    0
    Views:
    455
    Scott Allen
    Jul 13, 2004
  2. blue

    Checking File Permissions

    blue, Jul 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    387
    Ken Cox [Microsoft MVP]
    Jul 15, 2004
  3. Anoop

    Checking File permissions

    Anoop, Jul 20, 2006, in forum: Python
    Replies:
    1
    Views:
    280
    Lawrence D'Oliveiro
    Jul 21, 2006
  4. Anoop

    Checking File permissions

    Anoop, Jul 20, 2006, in forum: Python
    Replies:
    1
    Views:
    290
    Larry Bates
    Jul 20, 2006
  5. David K. Wall

    checking effective file permissions

    David K. Wall, Aug 9, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    110
    Glenn Jackman
    Aug 10, 2004
Loading...

Share This Page