在远程计算机上打开TextFile
我正在尝试使用此代码读取远程文本文件:
function defdate(ipaddress)
deffilePath = chr(34) & "\\" & ipaddress & "\c$\" & deffileName & chr(34)
wscript.echo deffilePath
set deffile = objFSO.OpenTextFile(deffilePath)
do while not deffile.endofstream
s=deffile.readline
wscript.echo s
loop
deffile.close
end function
下面的我的 deffilePath 扩展为如下字符串:
"\\10.211.19.207\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"
但是,我收到“Microsoft VBScript 运行时错误:文件名或编号错误”。
可能是什么问题呢?
I'm trying to read remote text files using this code:
function defdate(ipaddress)
deffilePath = chr(34) & "\\" & ipaddress & "\c$\" & deffileName & chr(34)
wscript.echo deffilePath
set deffile = objFSO.OpenTextFile(deffilePath)
do while not deffile.endofstream
s=deffile.readline
wscript.echo s
loop
deffile.close
end function
My deffilePath below expands into strings like this:
"\\10.211.19.207\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"
However, I get "Microsoft VBScript runtime error: Bad file name or number".
What could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您不需要(阅读:“不得”)将您的路径括在引号中。
You don't need to (read: "must not") enclose your path in quotes.
您只需要在使用命令行或类似 API 时包含引号 - CHR(34)。 如果一个方法只需要一个文件名,请将它们省略。
You only need to include the quotes -- the CHR(34) -- when using the command-line, or for similar APIs. If a method takes just a filename, leave them out.
问题是开头和结尾的“chr(34)”。 在 Windows 运行菜单中键入路径时,您需要这些引号,但是当将路径传递给这样的函数调用时,您不需要它们。
The problem is the "chr(34)" at the beginning and the end. When typing a path in the Windows run menu you need those quotes, but when passing a path to a function call like this you don't want them.
您是否尝试过删除末尾的 chr(34) ?
Have you tried removing the chr(34) at the end?
我认为 UNC 路径名开头需要两个反斜杠。 尝试添加另一个!
我的猜测是它适用于“\\10.211.19.207\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat”。
I think you need two backslashes at the start of an UNC pathname. Try adding another one!
My guess would be that it works with "\\10.211.19.207\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat".