Is a File a Subdirectory of Another Directory

F

Fuzzyman

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

F. GEIGER

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
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top