Using Apis

  • Thread starter Thread starter Silvester
  • Start date Start date
S

Silvester

Hi,

Before starting my A2000 app I would like to verify
1. existence of myvital.dll
2. filesize of myvital.dll

How can I code this using apis ?
 
Is there a reason that you need to use the API's?

To find if the file exists you can use the dir function e.g. if
len(dir("C:\myvital.dll")) then .... else .... End if

Unfortunately I don't know of any inbuilt functions for determining the size
of file but you can use the FileSystemObject (FSO) in the Scripting Runtime
to do this for you, if your using the FSO for the size then you can also use
it for checking if the file exists:

Dim oFSO As FileSystemObject
Dim oFile As File
Dim sPath As String

Set oFSO = New FileSystemObject

sPath = "C:\myvital.dll"

If oFSO.FileExists(sPath) Then
Set oFile = oFSO.GetFile(sPath)
MsgBox oFile.Size
Else
MsgBox ("File missing")
End If

If you still want to use API's then your best bet is FindFirstFile and
GetFileSize(Win 95,98,Me, NT 3.51) or GetFileSizeEX (Win 2k, XP)
 
Despite what the other posters have said, it's not necessary to use FSO to
do what you're trying to do (and, in my opinion, it's not desirable to use
FSO unless you must: it introduces unnecessary overhead, and there can be
versioning problems)

Here's Nikos's function rewritten without using FSO

Function filesize(fname As String) As Long

If Len(Dir(fname)) > 0 Then
filesize = FileLen(fname)
Else
filesize = -1
End If

End Function
 
Back
Top