DECLARE FUNCTION DeleteFile LIB "kernel32.dll" ALIAS "DeleteFileA" (BYVAL lpFileName AS STRING) AS LONG
DECLARE FUNCTION CloseHandle LIB "kernel32" ALIAS "CloseHandle" (BYVAL hObject AS LONG) AS LONG
TYPE FILETIME
dwLowDateTime AS DWORD
dwHighDateTime AS DWORD
END TYPE
DECLARE FUNCTION GetFileTime LIB "kernel32.dll" ALIAS "GetFileTime" (BYVAL hFile AS LONG,byref lpCreationTime AS FILETIME,byref lpLastAccessTime AS FILETIME,byref lpLastWriteTime AS FILETIME) AS LONG
DECLARE FUNCTION CompareFileTime LIB "kernel32.dll" ALIAS "CompareFileTime" (lpFileTime1 AS FILETIME, lpFileTime2 AS FILETIME) AS LONG
DECLARE SUB GetSystemTimeAsFileTime LIB "kernel32.dll" ALIAS "GetSystemTimeAsFileTime" (byref lpSystemTimeAsFileTime AS FILETIME)
DECLARE FUNCTION GetFileSize LIB "kernel32.dll" ALIAS "GetFileSize" (BYVAL hFile AS LONG, byref lpFileSizeHigh AS LONG) AS LONG
Public CONST OPEN_EXISTING = 3
Public CONST FILE_SHARE_READ = &H1
Public CONST GENERIC_READ = &H80000000
TYPE SECURITY_ATTRIBUTES
nLength AS LONG
lpSecurityDescriptor AS LONG
bInheritHandle AS LONG
END TYPE
DECLARE FUNCTION CreateFile LIB "kernel32" ALIAS "CreateFileA" (BYVAL lpFileName AS STRING, BYVAL dwDesiredAccess AS LONG, BYVAL dwShareMode AS LONG, lpSecurityAttributes AS SECURITY_ATTRIBUTES, BYVAL dwCreationDisposition AS LONG, BYVAL dwFlagsAndAttributes AS LONG, BYVAL hTemplateFile AS LONG) AS LONG
CONST bit32 AS DOUBLE=2^32
CONST bit31 AS DOUBLE=2^31
FUNCTION timestamp(t AS filetime) AS DOUBLE
DEFDBL dlow=(t.dwLowDateTime AND &h7fffffff),dhigh=t.dwHighDateTime*bit32
IF (t.dwLowDateTime AND &h80000000)<>0 THEN dlow+=bit31
timestamp=dhigh + dlow
END FUNCTION
CONST dayticks AS DOUBLE =24*60*60*1000*10000
FUNCTION daydiff(dd1 AS DOUBLE,dd2 AS DOUBLE) AS DOUBLE
daydiff=(dd2-dd1)/dayticks
END FUNCTION
FUNCTION FileDateTime(f AS STRING) AS DOUBLE
DIM t1 AS filetime,t2 AS filetime, t3 AS filetime
DEFLNG fh
fh=createfile(f,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING, _
FILE_ATTRIBUTE_ARCHIVE OR FILE_ATTRIBUTE_HIDDEN OR FILE_ATTRIBUTE_READONLY _
OR FILE_ATTRIBUTE_SYSTEM,0)
IF getfiletime(fh,t1,t2,t3)=0 THEN
filedatetime=0
ELSE
filedatetime=timestamp(t3)
END IF
closehandle fh
END FUNCTION
FUNCTION now() AS DOUBLE
DIM t0 AS filetime
GetSystemTimeAsFileTime(t0)
now=timestamp(t0)
END FUNCTION
FUNCTION filelen(f AS STRING) AS LONG
DEFLNG fh,sizeh
fh=createfile(f,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING, _
FILE_ATTRIBUTE_ARCHIVE OR FILE_ATTRIBUTE_HIDDEN OR FILE_ATTRIBUTE_READONLY _
OR FILE_ATTRIBUTE_SYSTEM,0)
IF fh=-1 THEN
result=-1
ELSE
result= getfilesize(fh,sizeh)
END IF
closehandle fh
END FUNCTION
|