Funkce FileExists vrátí True/False podle toho, zda soubor existuje či nikoliv. Reakce na případnou neexistenci souboru už je na vás.
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Public Const OFS_MAXPATHNAME = 128
Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Function FileExists(FileName As String) As Boolean
Dim RetCode As Integer
Dim OpenFileStructure As OFSTRUCT
Const OF_EXIST = &H4000
Const FILE_NOT_FOUND = 2
RetCode = OpenFile(FileName$, OpenFileStructure, OF_EXIST)
If OpenFileStructure.nErrCode = FILE_NOT_FOUND Then
FileExists = False
Else
FileExists = True
End If
End Function
|