473,387 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is a File a Subdirectory of Another Directory

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
1 1844
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Todd Johnson | last post by:
Hey, I have been working on a program that stores information for each user in a subdirectory of the directory in which the script is run. So if my script is in /home/someuser/myprogram, the...
1
by: Alex VanderWoude | last post by:
I am trying to <include> some text into an XML documentation topic, but that text is stored in a file that is in a different directory than the "current" XML file. Using a relative path does not...
4
by: who be dat? | last post by:
I feel stupid for asking this but I can't figure this out. I've got some text files I want my website to read. The text files are located in a subdirectory of my application. Physically, the...
3
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images ...
1
by: Peter Thorne | last post by:
I am a perl newbie who is trying to write a script to automate a task. I have a large collection of compressed archives (mostly .tar.gz, tar.bz2, tar.Z, .tgz etc). This are stored in a number...
12
by: pac | last post by:
I'm preparing to distribute a Windows XP Python program and some ancillary files, and I wanted to put everything in a .ZIP archive. It proved to be inordinately difficult and I thought I would...
1
by: John | last post by:
Hi, Trying to troubleshoot a web app. I'm getting the usual "set your web.config file to customErrors mode="Off"" message. Anyway, I DO have a web.config file in the root of the app, but it's...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: John Nagle | last post by:
Some obscure import issues: I'm running Python 2.3.4 from a CGI script on a shared hosting Linux system. The CGI program is being executed from Apache, as "nobody". I have some local modules...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.