在远程计算机上打开TextFile

发布于 2024-07-13 14:34:44 字数 580 浏览 3 评论 0原文

我正在尝试使用此代码读取远程文本文件:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

默嘫て 2024-07-20 14:34:44

您不需要(阅读:“不得”)将您的路径括在引号中。

deffilePath = "\\" & ipaddress & "\c$\" & deffileName

You don't need to (read: "must not") enclose your path in quotes.

deffilePath = "\\" & ipaddress & "\c$\" & deffileName
余生一个溪 2024-07-20 14:34:44

您只需要在使用命令行或类似 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.

巴黎盛开的樱花 2024-07-20 14:34:44

问题是开头和结尾的“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.

内心激荡 2024-07-20 14:34:44

您是否尝试过删除末尾的 chr(34) ?

Have you tried removing the chr(34) at the end?

酒中人 2024-07-20 14:34:44

我认为 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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文