2012-04-02 84 views
1

VBscript新手和花太多时间试图找到正确的方式来打开文件进行阅读。无论我尝试过,我总是得到“找不到路径”错误。在VBscript中指定文件路径的正确方法是什么?

这是我的文件真实路径: d:\ INETPUB \虚拟主机\ lamardesigngroup.com \的httpdocs \

,我尝试运行的文件是: d:\ INETPUB \虚拟主机\ lamardesigngroup .COM \的httpdocs \ IFP \ files.asp

,我想读这个文件: d:\ INETPUB \虚拟主机\ 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”

我也试过

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 

我明明输了...

回答

2

上午哈雷,

试试看:

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

它应该导致识别您的特定服务器位置。我遇到了这个问题,试图让一些vbscript文件上传代码工作。它应该从您的页面正在工作的文件夹开始并从那里开始。

+0

哇!我用第二个和BANG!有我的文件。谢谢!我应该问这个星期六:) – 2012-04-02 16:28:22

+1

@哈利如果这解决了你的问题,请勾选绿色的V图标左侧接受标记为接受。 :) – 2012-04-03 06:13:07

相关问题