Relative path when using vbscript in webpage

February 4, 2010 at 08:50:49
Specs: Windows XP
Hi there,
I am really struggling to get this to work.
I have a small vbscript that runs in a webpage (complete htm file shown below), reads a text file and based on that value, outputs a message in the webpage.

Everything works fine if I use the absolute path for reading the file (out.txt)

But there is no way I can get this to work without absolute path.

Note that my run.htm file (shown below) and out.txt will be in the same directory. My guess was that “.\” should have worked but I have tried every possible combination and it never works.
This is the line in the file below that I cannot get right
Set iFile = fso.OpenTextFile ("c:\11\out.txt", ForReading)

I would really appreciate some guidance.

Kind Regards


<script type="text/vbscript">
dim fso
Set fso = createobject("Scripting.FileSystemObject")
Set Folder = fso.GetFolder(Path1)
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
' .\test
Set iFile = fso.OpenTextFile ("c:\11\out.txt", ForReading)
do while iFile.AtEndOfStream=false
if (x="1") then
document.write "

document.write "

end if

See More: Relative path when using vbscript in webpage

Report •

February 8, 2010 at 05:47:09
To know why your relative path doesn't work, you must first know what your current path is. This line should tell you:
document.write fso.GetFolder(".").Path & "<br />"

Report •

February 8, 2010 at 11:33:12
it has something to do with being wrapped into html, because it works ok as a standalone vbs.

Report •
Related Solutions

Ask Question