FILE_DATE_TIME

 
Author Page created on Page updated on
Jacques Paris 21.03.03
 
DLL calls used by this example

Type SECURITY_ATTRIBUTES

Type FILETIME

Type SYSTEMTIME

CreateFile()

CloseHandle()

FileTimeToLocalFileTime()

FileTimeToSystemTime()

GetFileTime()

 
Download available as:
 
MapBasic . Copy/Paste to a new MB page if needed, or download if available.

Type FILETIME

   dwLowDateTime As Integer

   dwHighDateTime As Integer

End Type

 

Type SYSTEMTIME

   wYear As Smallint

   wMonth As Smallint

   wDayOfWeek As Smallint

   wDay As Smallint

   wHour As Smallint

   wMinute As Smallint

   wSecond As Smallint

   wMilliseconds As Smallint

End Type

 

Type SECURITY_ATTRIBUTES

   nLength As Integer

   lpSecurityDescriptor As Integer

   bInheritHandle As Logical

End Type

 

Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (

   ByVal lpFileName As String,

   ByVal dwDesiredAccess As Integer,

   ByVal dwShareMode As Integer,

   lpSecurityAttributes As SECURITY_ATTRIBUTES,

   ByVal dwCreationDisposition As Integer,

   ByVal dwFlagsAndAttributes As Integer,

   ByVal hTemplateFile As Integer) As Integer

 

Declare Function CloseHandle Lib "kernel32.dll" (

   ByVal hObject As Integer) As Integer

 

Declare Function FileTimeToLocalFileTime Lib "kernel32.dll" (

   lpFileTime As FILETIME,

   lpLocalFileTime As FILETIME) As integer

 

Declare Function FileTimeToSystemTime Lib "kernel32.dll" (

   lpFileTime As FILETIME,

   lpSystemTime As SYSTEMTIME) As Integer

 

Declare Function GetFileTime Lib "kernel32.dll" (

   ByVal hFile As Integer,

   lpCreationTime As FILETIME,

   lpLastAccessTime As FILETIME,

   lpLastWriteTime As FILETIME) As Integer

 

'=================================================================

Dim hFile As Integer      ' handle to the opened file

Dim ctime As FILETIME     ' receives time of creation

Dim atime As FILETIME     ' receives time of last access

Dim mtime As FILETIME     ' receives time of last modification

Dim thetime As SYSTEMTIME ' used to manipulate the time

Dim retval As Integer     ' return value

dim a_sec as Security_Attributes 'required for the createfile function

dim afile as string       'to hold the file path/name

 

' Get the handle for the file

afile=fileopendlg("","","","File to query")

if afile="" then exit sub end if

hFile = CreateFile(afile, &H80000000, &H1, a_sec, 3, &H20, 0)

If hFile = -1 Then Print "Could not open the file successfully -- aborting." Exit sub End If

 

' Get the creation, last-access, and last-modification times.

retval = GetFileTime(hFile, ctime, atime, mtime)

 

' Convert the creation time to the local time zone. To get last-access

' last-modification, repeat the conversion for each 'time'

retval = FileTimeToLocalFileTime (ctime, ctime)

 

' Convert the FILETIME format to the SYSTEMTIME format.

retval = FileTimeToSystemTime (ctime, thetime)

 

' Display the date and time of creation of the file

Note afile+chr$(10)+"was created on "+str$(thetime.wMonth)+ "-"+ thetime.wDay+ "-"+ thetime.wYear

+" at "+str$(thetime.wHour)+":"+str$(thetime.wMinute)+":"+str$(thetime.wSecond)

 

' Close the file to free up resources.

retval = CloseHandle(hFile)

 
Comments:

Returns the create date/time of a single file. For complete info on other dates/times and size of a single file or a set of files see the File_Set_Info example