vbscript fileexist错误

时间:2012-08-16 13:01:05

标签: vbscript

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

这是我的代码:

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)

以上都没有?任何建议都受到高度赞赏。

亲切的问候, 扎因

1 个答案:

答案 0 :(得分:2)

我不确定您要对filespec vs 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)