Page 1 of 1

File Info ~ Created On, Modified On, Last Accessed

Posted: Mon Jan 05, 2004 10:18 am
by boop64
Here is some simple code to get simple file info like when the file was created, modified or accessed last. The code is pretty straight forward and uses the following windows API calls I will put them in purebasic terms.

GetFileTime_(FileID , A, B, C)
FileID = Result obtained from using OpenFile(), ReadFile(), UseFile() etc.
A = FILETIME structure to get the date and time the file was created.
B = FILETIME structure to get the date and time the file was last accessed.
C = FILETIME structure to get the date and time the file was last modified.

FileTimeToLocalFileTime_(A, B)
A = One of the FILETIME structures previously used in the GetFileTime_() function to be converted into a local file time.
B = FILETIME structure to store converted file time.

FileTimeToSystemTime_(A, B)
A = FILETIME structure with local file time to be converted to system time.
B = SYSTEMTIME structure to store converted system time.

Well I hope this helps someone.

Boop64

Code: Select all

;|---------------------|
;|  Coded By: Boop64   |
;|http://www.boop64.net|
;|---------------------|
;Structure FILETIME
;    dwLowDateTime.l
;    dwHighDateTime.l
;EndStructure

;Structure SYSTEMTIME
;    wYear.w
;    wMonth.w
;    wDayOfWeek.w
;    wDay.w
;    wHour.w
;    wMinute.w
;    wSecond.w
;    wMilliseconds.w
;EndStructure 
;I left the structres commented here so that you can see what variables are acctually in them
;so that you can modify this code for your purposes.
;To use this just include in your projects.

Procedure.s WeekDay(day) 
Select day
Case 0
wday$ = "Sunday"
Case 1
wday$ = "Monday"
Case 2
wday$ = "Tuesday"
Case 3
wday$ = "Wedsday"
Case 4
wday$ = "Thursday"
Case 5
wday$ = "Friday"
Case 6
wday$ = "Saturday"
EndSelect
ProcedureReturn wday$
EndProcedure 

Procedure.s ModifiedOn(File$)
F1.FILETIME
F2.FILETIME
S1.SYSTEMTIME 
fileid.l = ReadFile(0, File$)
GetFileTime_(fileid , #NULL, #NULL, F2)
FileTimeToLocalFileTime_(F2, F1)
FileTimeToSystemTime_(F1, S1) 

fileinfo$ = WeekDay(S1\wDayOfWeek) +" " + Str(S1\wMonth) +"/"+ Str(S1\wDay) +"/"+ Str(S1\wYear)
CloseFile(0)
ProcedureReturn fileinfo$
EndProcedure

Procedure.s LastAccess(File$)
F1.FILETIME
F2.FILETIME
S1.SYSTEMTIME 
fileid.l = ReadFile(0, File$)
GetFileTime_(fileid , #NULL, F2, #NULL)
FileTimeToLocalFileTime_(F2, F1)
FileTimeToSystemTime_(F1, S1) 

fileinfo$ = WeekDay(S1\wDayOfWeek) +" " + Str(S1\wMonth) +"/"+ Str(S1\wDay) +"/"+ Str(S1\wYear)
CloseFile(0)
ProcedureReturn fileinfo$
EndProcedure

Procedure.s CreatedOn(File$)
F1.FILETIME
F2.FILETIME
S1.SYSTEMTIME 
fileid.l = ReadFile(0, File$)
GetFileTime_(fileid , F2, #NULL, #NULL)
FileTimeToLocalFileTime_(F2, F1)
FileTimeToSystemTime_(F1, S1) 

fileinfo$ = WeekDay(S1\wDayOfWeek) +" " + Str(S1\wMonth) +"/"+ Str(S1\wDay) +"/"+ Str(S1\wYear)
CloseFile(0)
ProcedureReturn fileinfo$
EndProcedure


MessageRequester("Created On", CreatedOn("Test.exe"))
MessageRequester("Last Accessed", LastAccess("Test.exe"))
MessageRequester("Modified On", ModifiedOn("Test.exe"))