在VBscript中指定文件路径的正确方法是什么? [英] What's the correct way to specify file path in VBscript?
问题描述
VBscript的新手,花费太多时间试图找到打开文件进行读取的正确方法.无论我尝试了什么,我总是会收到找不到路径"错误.
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.
这是我文件的真实路径: D:\ InetPub \ vhosts \ lamardesigngroup.com \ httpdocs \
This is the real path to my files: D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\
我要运行的文件是: D:\ InetPub \ vhosts \ lamardesigngroup.com \ httpdocs \ ifp \ files.asp
The file that I am trying to run is: D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\files.asp
,我想读取此文件: D:\ InetPub \ vhosts \ lamardesigngroup.com \ httpdocs \ ifp \ css \ style.css
and I want to read this file: D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\css\style.css
这是代码:
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
我得到"12 | 800a004c | Path_not_found 80"
and I get "12|800a004c|Path_not_found 80"
我也尝试过
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
我显然迷路了...
推荐答案
哈雷早上,
尝试一下:
strTextFile = server.MapPath("css/style.css")
它应该可以识别您的特定服务器位置.我遇到了这个问题,试图使某些vbscript文件上传代码正常工作.它应该从您的页面正在使用的文件夹开始,然后从那里开始.
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.
这篇关于在VBscript中指定文件路径的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!