What's the correct way to specify file path in VBscript?

丶灬走出姿态 提交于 2020-01-15 10:15:08

问题


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.



来源:https://stackoverflow.com/questions/9979895/whats-the-correct-way-to-specify-file-path-in-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!