Is a File a Subdirectory of Another Directory

Discussion in 'Python' started by Fuzzyman, Feb 13, 2004.

  1. Fuzzyman

    Fuzzyman Guest

    I wish to restrict access to a program to certain directories. I also
    wish to prevent access to certain directories.

    What this means is that given a path, I need to work out if that path
    is in a certain directory... or in a subdirectory of that directory.
    (On a Linux server).

    The only way I can think of so far is to turn both paths into absolute
    paths, strip off the filename and compare... is this the most elegant
    way ?

    Fuzzy

    http://www.voidspace.org.uk/atlantibots/pythonutils.html
    Fuzzyman, Feb 13, 2004
    #1
    1. Advertising

  2. Fuzzyman

    F. GEIGER Guest

    I work with absolute paths only. I once had written classes DirName and
    PathName :)= DirName + FileName) and always use them for such operations.

    Within my apps I can ask questions like yours like so:
    if str(anyPath.dn()).startswith(str(anyDirName)):
    print "Sorry, access restricted. "

    Or w/o conv. to a string:
    if anyPath.dn().startswith(anyDirName):
    print "Sorry, access restricted. "

    HTH
    Franz GEIGER

    "Fuzzyman" <> schrieb im Newsbeitrag
    news:...
    > I wish to restrict access to a program to certain directories. I also
    > wish to prevent access to certain directories.
    >
    > What this means is that given a path, I need to work out if that path
    > is in a certain directory... or in a subdirectory of that directory.
    > (On a Linux server).
    >
    > The only way I can think of so far is to turn both paths into absolute
    > paths, strip off the filename and compare... is this the most elegant
    > way ?
    >
    > Fuzzy
    >
    > http://www.voidspace.org.uk/atlantibots/pythonutils.html
    F. GEIGER, Feb 13, 2004
    #2
    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. Dave Mitchell

    Re: subdirectory settings

    Dave Mitchell, Jul 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    383
    Dave Mitchell
    Jul 15, 2003
  2. moon
    Replies:
    3
    Views:
    8,968
    Thomas Fritsch
    Sep 20, 2005
  3. Loane Sharp
    Replies:
    1
    Views:
    773
    Bernard Cheah [MVP]
    Apr 24, 2006
  4. Replies:
    11
    Views:
    425
    Peter Otten
    Mar 2, 2007
  5. lofenee
    Replies:
    3
    Views:
    128
    Ben Bullock
    Apr 22, 2008
Loading...

Share This Page