Is a File a Subdirectory of Another Directory

F. GEIGER fgeiger at datec.at
Fri Feb 13 07:39:08 EST 2004


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" <michael at foord.net> schrieb im Newsbeitrag
news:8089854e.0402130119.7c55e9a2 at posting.google.com...
> 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





More information about the Python-list mailing list