September 21, 2020, 02:44:30 am

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


FileDateTIme comparison

Started by exjoburger, September 05, 2007, 11:05:51 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

exjoburger

How do I compare the filedatetime of two files in Creative BASIC?

Thanks

Ionic Wind Support Team

Perhaps this will be of some use:

Code Select

'How to retrieve creation, access and write date/time of a file
'This program retrieves all three values and displays the
'creation date in a message box

'some useful values
SETID "OPENEXISTING",3
SETID "GENERICREAD",0x80000000
SETID "GENERICWRITE",0x40000000

'All files store the date/times in
'a simple long integer
TYPE FILETIME
def dwLowDateTime:int
def dwHighDateTime:int
ENDTYPE
'The systemtime type is easier to work with
type SYSTEMTIME,2
def wYear:WORD
def wMonth:WORD
def wDayOfWeek:WORD
def wDay:WORD
def wHour:WORD
def wMinute:WORD
def wSecond:WORD
def wMilliseconds:WORD
endtype
'The neccessary windows functions
DECLARE "Kernel32",CreateFileA(name:string,access:int,share:int,security:int,create:int,flags:int,handle:int),int
DECLARE "Kernel32",CloseHandle(handle:int),int
DECLARE "Kernel32",GetFileTime(handle:int,creation:filetime,access:filetime,writet:filetime),int
DECLARE "Kernel32",FileTimeToSystemTime(timef:filetime,times:SYSTEMTIME),int

DEF filename,out:string
DEF hfile:int
DEF creation,access,writet:filetime
DEF times:SYSTEMTIME

filename = FILEREQUEST("Pick a file",0,1)
'open the file with READ access. If the file doesn't exist
'the function returns null (0)
hFile = CreateFileA(filename,@GENERICREAD,0,0,@OPENEXISTING,0,0)
if(hfile)
'get the three date/times
if(GetFileTime(hfile,creation,access,writet))
'convert the filetime to a systemtime type
FileTimeToSystemTime(creation,times)
out = "Creation Date: "+ ltrim$(str$(times.wMonth)) + "-" + ltrim$(str$(times.wDay)) + "-" + ltrim$(str$(times.wYear))
messagebox 0,out,"Result"
endif
'close the file
CloseHandle(hfile)
endif

end
Ionic Wind Support Team

Ionic Wind Support Team

And along the same lines this one gets a files size without opening it.

Code Select

'works on all systems
TYPE WIN32FINDDATA
    def dwFileAttributes as UINT
    def ftCreationTime as UINT64
    def ftLastAccessTime as UINT64
    def ftLastWriteTime as UINT64
def fileSizeH as UINT
def fileSizeL as UINT
def reserved as UINT64
    def cFileName[ 260 ] as CHAR
    def cAlternateFileName[ 14 ] as CHAR
ENDTYPE

DECLARE "kernel32",FindFirstFileA(name as STRING,pfd as memory),UINT
DECLARE "kernel32",WIN32FindClose ALIAS FindClose(handle as UINT),int
DEF pfd as MEMORY
DEF fd as WIN32FINDDATA
DEF handle as UINT
DEF size as UINT64
ALLOCMEM pfd,1,len(fd)

handle = FindFirstFileA("c:\autoexec.bat",pfd)
if(handle)
READMEM pfd,1,fd
size = fd.fileSizeL | (fd.fileSizeH * (2^32))
PRINT "autoexec file size = ",size,"bytes"
WIN32FindClose(handle)
endif

print "press any key to close"
do:until inkey$<>""
closeconsole:end




Code Select

'only works on NT,2000 and XP

TYPE WIN32FADATA
    def dwFileAttributes as UINT
    def ftCreationTime as UINT64
    def ftLastAccessTime as UINT64
    def ftLastWriteTime as UINT64
def fileSize as UINT64
ENDTYPE

DECLARE "kernel32",GetFileAttributesExA(name as string,id as int,attributes as WIN32FADATA),int
DEF fa as WIN32FADATA

GetFileAttributesExA("c:\autoexec.bat",0,fa)

PRINT "autoexec file size = ",fa.fileSize,"bytes"

print "press any key to close"
do:until inkey$<>""
closeconsole:end
Ionic Wind Support Team