What's the correct way to specify file path in

2019-08-15 04:10发布

问题:

New to VBscript and spending way too much time trying to find the right way to open a file for reading. Whatever I've tried I always get "Path not found" error.

This is the real path to my files: D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\

The file that I am trying to run is: D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\files.asp

and I want to read this file: D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\css\style.css

Here is the code:

Dim objFSO, strTextFile, strData, strLine, arrLines
CONST ForReading = 1

'name of the text file
strTextFile = "//css/style.css"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Step through the lines
For Each strLine in arrLines
    response.write(strLine & "<br>")
Next

'Cleanup
Set objFSO = Nothing

and I get "12|800a004c|Path_not_found 80"

I've also tried

strTextFile = "D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\css\style.css"

' and 
strTextFile = "\\css\style.css"
strTextFile = "css\style.css"
strTextFile = "css/style.css"

' and many other combinations

I'm obviously lost...

回答1:

Morning Harley,

Give this a try:

strTextFile = server.MapPath("css/style.css")

It should result in recognizing your specific server location. I ran into this problem trying to get some vbscript file upload code to work. It should start from the folder your page is working in and go from there.