tags:

views:

59

answers:

3

Hello, I'm trying to create a simple VBS script, in this I need a Function that takes a file path and returns true if there is a file there, and false if there's nothing.

I'm using the following code

Function FileThere (FileName As String) As Boolean
FileThere = (Dir(FileName) > "")
End Function

I get the following Error

Expected ')'
800A03EE
Microsoft VBScript compilation error

Any idea what's wrong? I've tested it with just those three lines in the file and the error still occurs.

+1  A: 

VBScript only has the variant type, you can't specify types explicitly.

Function FileThere(FileName)
    FileThere = (Dir(FileName) > "")
End Function
Julien Lebosquain
+1  A: 

You must remove variable types. BTW, Dir() function isn't available so you must go with following code:


Function FileThere (FileName) 
    Set fso = CreateObject("Scripting.FileSystemObject")
    FileThere = fso.FileExists(FileName)
    Set fso = Nothing
End Function

Rubens Farias
+1  A: 
  1. there are no types as such in vbs

  2. Dir function does not exist.

    Function FileThere(FileName)

    Dim fso

    Set fso = CreateObject("Scripting.FileSystemObject")

    FileThere = fso.FileExists(FileName)

    set fso=nothing

    End Function

    wscript.echo FileThere("c:\boot.ini")

DmitryK