Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is a File a Subdirectory of Another Directory

Reply
Thread Tools

Is a File a Subdirectory of Another Directory

 
 
Fuzzyman
Guest
Posts: n/a
 
      02-13-2004
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
 
Reply With Quote
 
 
 
 
F. GEIGER
Guest
Posts: n/a
 
      02-13-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" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To find a quick way to list all files in the directory(and subdirectory) lofenee Perl Misc 3 04-22-2008 05:57 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Walk thru each subdirectory from a top directory silverburgh.meryl@gmail.com Python 11 03-02-2007 09:33 AM
delete wwwroot subdirectory and virtual directory when web application is uninstalled Loane Sharp ASP .Net 1 04-24-2006 02:27 AM
Java Program delete files in directory also include subdirectory moon Java 3 09-20-2005 01:31 PM



Advertisments