开发者

Problem creating a VBScript function

I'm trying to create a simple VBScript 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(Fil开发者_如何学GoeName) > "")
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.


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


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

Function FileThere(FileName)
    FileThere = (Dir(FileName) > "")
End Function


  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")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜