0

我正在尝试检查文件是否存在/链接是否存在,如下所示:没有成功

这是我的代码:

filespec = "C:\Users\xyz\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"&"\Internet Explorer.lnk"

filespec1 = char(34)&"C:\Users\xyz\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"&"\Internet Explorer.lnk" &char(34)


Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
  msg = filespec & " exists."
Else
  msg = filespec & " doesn't exist."
End If
WScript.Echo(msg)


If (fso.FileExists(filespec1)) Then
  msg = filespec1 & " exists."
Else
  msg = filespec1 & " doesn't exist."
End If
WScript.Echo(msg)

以上都不起作用?任何建议都受到高度赞赏。

亲切的问候,赞恩

4

1 回答 1

2

我不确定你想用filespecvs做什么filespec1,但第一个问题char不是 VB Script 关键字。你需要使用Chr.

filespec1 = Chr(34) & "C:\Users\xyz\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" & "\Internet Explorer.lnk" & Chr(34)

更新 1

这是我成功运行的代码。这是您的原始代码,char替换为Chr.

filespec = "C:\Users\xyz\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"&"\Internet Explorer.lnk"

filespec1 = Chr(34) & "C:\Users\xyz\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"&"\Internet Explorer.lnk" & Chr(34)


Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
  msg = filespec & " exists."
Else
  msg = filespec & " doesn't exist."
End If
WScript.Echo(msg)


If (fso.FileExists(filespec1)) Then
  msg = filespec1 & " exists."
Else
  msg = filespec1 & " doesn't exist."
End If
WScript.Echo(msg)
于 2012-08-16T13:21:13.377 回答