Question : FileExists WinAPI - Delphi

Hello Experts,
I need to know how to use WinAPI to check if file exists or not,
other way is to get file age and determine if the age is valid or not (-1 = not Exists)

- Size metter.
- Should be called from a dll not from  SysUtils,

I made some research and i found only VB code using WinAPI
so if anyboddy can to translate it or port it to Delphi i will be verry gracefull

http://www.freevbcode.com/ShowCode.asp?ID=345

Thanks in advace,
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
Declarations:
' #VBIDEUtils#**************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : [email protected]
' * Date             : 28/06/99
' * Time             : 12:24
' **************************************************************
' * Comments         : API FileExist
' *
' *
' ****************************************************************

Option Explicit

Private Const INVALID_HANDLE_VALUE = -1
Private Const MAX_PATH = 260

Private Type FILETIME
   dwLowDateTime As Long
   dwHighDateTime As Long
End Type

Private Type WIN32_FIND_DATA
   dwFileAttributes As Long
   ftCreationTime As FILETIME
   ftLastAccessTime As FILETIME
   ftLastWriteTime As FILETIME
   nFileSizeHigh As Long
   nFileSizeLow As Long
   dwReserved0 As Long
   dwReserved1 As Long
   cFileName As String * MAX_PATH
   cAlternate As String * 14
End Type

Private Declare Function FindFirstFile Lib "kernel32" _
   Alias "FindFirstFileA" _
   (ByVal lpFileName As String, _
   lpFindFileData As WIN32_FIND_DATA) As Long

Private Declare Function FindClose Lib "kernel32" _
   (ByVal hFindFile As Long) As Long

Code:
'Usage: 
'dim bFileExists as boolean
'bFileExists = FileExists("c:\win\system\comctl32.dll")
Public Function FileExists(sSource As String) As Boolean
   
   Dim WFD As WIN32_FIND_DATA
   Dim hFile As Long
   
   hFile = FindFirstFile(sSource, WFD)
   FileExists = hFile <> INVALID_HANDLE_VALUE
   
   Call FindClose(hFile)
   
End Function

Answer : FileExists WinAPI - Delphi

Random Solutions  
 
programming4us programming4us