Wednesday, February 9, 2011

Script to Check if file exists or not

'Check if file exists
On Error Resume Next
dim objFSO

strFile="c:\file.txt"
set objFSO=CreateObject("Scripting.FileSystemObject")

if objFSO.FileExists(strFile) then
   wscript.Echo strFile & " exists"
   'insert any other code you want to execute if file exists
else
   wscript.Echo "Cannot find " & strFile
   'insert any other code or error handling you want to execute
   'if file does not exist
end if

set objFSO=Nothing

No comments: