Article ID: 168519
Article Last Modified on 5/12/2003
'If using a 32-bit version of Visual Basic, this declaration is
'required;
Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _
lpReOpenBuff As OFSTRUCT, _
ByVal wStyle As Long) As Long
'If using the 16-bit version of Visual Basic 4.0, this declaration is
'required;
Declare Function OpenFile Lib "kernel" (ByVal lpFileName As String, _
lpReOpenBuff As OFSTRUCT, _
ByVal wStyle As Integer) _
As Integer
'Both 16-bit and 32-bit utilize these constants and structure:
Public Const OFS_MAXPATHNAME = 128
Public Const OF_EXIST = &H4000
Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
'On the VB IDE menu bar select Tools/Options/Project/Startup Form and
'set Sub Main() as the project start-up form.
Sub main()
Dim result As Integer
Dim strPath As String
Dim strucFname As OFSTRUCT
Dim strResults As String
Dim strSearchFile As String
strSearchFile = "\\ServerName\ShareName\Test"
result = OpenFile(strSearchFile, strucFname, OF_EXIST)
'The above line causes OpenFile to search for the
'file Test (no extension) on the server network path.
'Passing the OF_EXIST parameter tells the OpenFile
'function to search for the file, the file will not be
'opened or modified in any way.
If result <> -1 Then
MsgBox "File found"
Else
MsgBox "File not found"
End If
End Sub
112674 : How to Determine If a File Exists by Using DIR$
Keywords: kbapi kbprb KB168519