Advertisement

File Exists

Started by March 03, 2002 04:44 PM
3 comments, last by gamechampionx 22 years, 6 months ago
In VB6, how do I determine if a given file exists? I think it has something to do with the lenght of the string.
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
http://www.vbexplorer.com/tips/src34.asp

,Jay
Advertisement
The site doesn''t work. It loads, then the error screen comes up. Can anyone tell me how to determine if a file exists in VB6?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
I''m pretty sure you use the function Dir(). You pass it the name of the file you''re looking for, and check the return value. If it is equal to "" then the file doesn''t exist.

Try somthing like this:

Dim file As String
file = "document.txt"

If Dir(file) = "" Then
''The file doesn''t exist
End If
here's a quick easy way:
Public Function FileExists(FileName As String) As Boolean    Dim NuM As Integer    NuM = FreeFile()    On Error GoTo FileExistsERROR    Open FileName For Input As NuM    Close NuM    FileExists = TrueFileExistsERROR:End Function  

you can also get a list of existing files with the dir$() function, and then search this list... but that would take longer to type in, heh heh...

EDIT: or what AP said...

Edited by - krez on March 5, 2002 4:01:56 PM
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

This topic is closed to new replies.

Advertisement