[thelist] (no subject)

Chris Marsh chris at webbtech.co.uk
Tue Nov 19 11:22:01 CST 2002


Jim

> I've been trying to find a way in VB Script to do the following:
>
> I have a file located in the following directory:
>
> C:\inetpub\wwwroot\dir1\subdir1\file.txt
>
> my ASP page is in:
>
> C:\inetpub\wwwroot\dir1\subdir2\file1.asp
>
> I want to open "file.txt" using OpenTextFile.  OpenTextFile
> requires an absolute path to the file.  My "file1.asp" is a
> template so the exact path will change depending on what
> directory the "file1.asp" template is saved to.
>
> Is there any way to determine what the abolute path of
> "file.txt" is from where "file1.asp" resides?

The strict answer is that there is no way to determine the path to file
A from the path to file B with no further information. However, if you
introduce a rule that all text files reside in the same directory as the
.asp file that is opening them, then you could do  something along the
following lines:

Dim sVirtualPath, sPhysicalPath
sVirtualPath = Request.ServerVariables("PATH_INFO")
sVirtualPath = Mid(sVirtualPath, 1, InStrRev(sVirtualPath, "/"))
sPhysicalPath = Server.MapPath(sVirtualPath)

Now you have the virtual and physical paths to the .asp page, thus the
virtual and physical paths to the text file. You can then make any other
changes to the path according to your structural rules.

If however there is no relationship between the location of the text
files and the .asp files; rather the location of the text files is
constant, then:

sPhysicalPath = Server.MapPath("/dir1/subdir1")

will give you the physical path.

HTH

Regards

Chris Marsh





More information about the thelist mailing list