By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

Is a File a Subdirectory of Another Directory

P: n/a
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/atlantib...thonutils.html
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <mi*****@foord.net> schrieb im Newsbeitrag
news:80**************************@posting.google.c om...
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/atlantib...thonutils.html

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.