PDA

View Full Version : How do I use a relative path with a FileSystemObject?


goldtwh
04-26-2009, 03:45 AM
My hosting manager says I should be using a relative path in the following code:
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("C:\Inetpub\Wwwroot\dir1\dir2\results.txt")

I have tried several combinations using the following code to get the absolute path:
Dim currentdirectorypath
currentdirectorypath = Server.MapPath(".")

Seems to me the following code should work:
Set file = fs.OpenTextFile(currentdirectorypath"\results.txt")

What am I doing wrong?

Is it wrong to use an absolute path?

Is it normal for the hosting manager to supply the absolute path shown above?

Old Pedant
04-26-2009, 11:16 PM
Yes, the code you show should work:

currentdirectorypath = Server.MapPath(".")
Set file = fs.OpenTextFile(currentdirectorypath"\results.txt")


*IF* !!

If you already have created the "fs" object used there.

If you mean that you want to open the file named "results.txt" IN THE SAME DIRECTORY as where your ASP code is running.

And your host is correct: There is clearly no guarantee that your absolute path will indeed *STAY* as "C:\Inetpub\Wwwroot\dir1\dir2\" Certainly on our host we are moved moderately often. Sometimes we are on C: drive, sometimes on E:, etc.

laganngurr
05-07-2009, 12:56 PM
http://www.top1gaming.com/cosplay/Gurren-Lagann-2.jpgSee the answer click here (http://www.top1gaming.com/coscontent-99-2.html). Want to see more pics (http://www.top1gaming.com/cosplayer.php)? Show yourself on our forum click here (http://www.top1gaming.com/forum/index.php?gid=27)Recommend:Final Fantasy X sexy Lulu (http://www.top1gaming.com/coscontent-224.html)Tinker bell Peter Pan sexy cosplay (http://www.top1gaming.com/coscontent-229.html)