Sorry if this question seems extremely basic (no punn intended) but I've
been reading 2 books on Visual Basic 6 and although they give good insight
into how fileio works with Visual Basic 6, they never really mention how to
check for existing files. They simply state that if the file exists then Vb
will do "blah blah" or if it doesn't then it will create it, depending on
the mode (random, binary etc.)
Does anyone know a good way to check if a file already exists? I would like
to set a varible = 1 if the file already exists so I can use that info later
in the program.
Thanks,
Joe
Public Function FileExists(ByVal FileName As String) As Boolean
'
Dim Attr As VbFileAttribute
On Error Resume Next
Attr = GetAttr(FileName)
If Err.Number <> 0 Then
FileExists = False
ElseIf (Attr And vbDirectory) Then
FileExists = False 'is directory
Else
FileExists = True 'exists, not a directory
End If
Err.Clear
On Error GoTo 0
End Function
"Joe" <dgtala...@hotmail.com> wrote in message
news:mjwe7.39096$7G.4...@typhoon.mw.mediaone.net...
FileExists = oFile.FileExists(szFileName)
Set oFile = Nothing
End Function
Steve Szudzik
http://www.szudzikfamily.com
"Joe" <dgtala...@hotmail.com> wrote in message
news:mjwe7.39096$7G.4...@typhoon.mw.mediaone.net...
Dim intFileExist as integer
Dim strFileName as string
strFileName=dir("c:\path\filename")
if strFileName <>"" then
intFileExist = 1
else
intFileExist = 0
endif
Regards
BD
On Wed, 15 Aug 2001 15:12:18 GMT, "Joe" <dgtala...@hotmail.com>
wrote:
*Never* use Dir in a 'core utility' routine - it interferes with other
Dir loops.
The FindFirstFile/FindNextFile API method is safe - but personally I
have been using (variations) of the GetAttr method since 1987 and have
found it absolutely fine.
As for using the FSO ... that really is a sledgehammer to crack a
hazelnut.
On Wed, 15 Aug 2001 19:43:06 +0100, BD <bd_jlr...@hotmail.com>
wrote:
Just wanted to thank you all. That was very helpful.
Joe
"Joe" <dgtala...@hotmail.com> wrote in message
news:mjwe7.39096$7G.4...@typhoon.mw.mediaone.net...