Reputation: 1
I am trying to check if file exists/link exists as follows: No sucess
Here is my code:
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)
None of the above works? Any suggestion is highly appreciated.
Kind regards, Zain
Upvotes: 0
Views: 373
Reputation: 20189
I'm not sure what you're trying to do with filespec
vs filespec1
, but the first problem is char
is not a VB Script keyword. You need to use Chr
.
filespec1 = Chr(34) & "C:\Users\xyz\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" & "\Internet Explorer.lnk" & Chr(34)
This is the code I ran successfully. It is your original code with char
replaced with 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)
Upvotes: 2