GetFileTime() and DateTime objects

About 

This PRG source code demonstrates usage of DateTime objects of The YUKON Project with the GetFileTime() API function. DateTime objects can be used whenever a FILETIME or SYSTEMTIME structure is required. A DateTime object can assume both structures.

GetFileTime.prg 
// FILE: GetFileTime.prg
// Copyright (c) Hannes Ziegler, 2008 
// This file is published as Open Source for The YUKON Project (www.knowleXbase.com)

#include "YukonSTC.ch"

PROCEDURE Main( cFileName )
   LOCAL nFileHandle := FOpen( cFileName, 0 )
   LOCAL oCreate, oAccess, oWrite

   IF Empty( cFileName )
      ? "Error: no file specified"
      QUIT
   ELSEIF FError() <> 0
      ? "File error:", DosErrorMessage( FError() )
      QUIT
   ENDIF

   // Prepare structures to pass to the API function
   oCreate := DateTime():new()
   oAccess := DateTime():new()
   oWrite  := DateTime():new()

   oCreate:toFileTime()  // The internal buffer of a DateTime object 
   oAccess:toFileTime()  // must be configured as FILETIME structure.
   oWrite:toFileTime()   // Default is SYSTEMTIME.
       
   // Call the API function from kernel32.dll
   KERNEL32.GetFileTime( nFileHandle, oCreate, oAccess, oWrite )

   // Close the file
   FClose( nFileHandle )

   ? "Creation date    :", oCreate:date, oCreate:time
   ? "Modification date:", oWrite:date , oWrite:time
   ? "Last access date :", oAccess:date, oAccess:time
   ?

  /*
    Output on my computer:
    Creation date    : 04/14/2008 13:32:07.031
    Modification date: 04/18/2008 22:49:32.250
    Last access date : 05/14/2008 11:44:26.234

    Note that time information is accurate to a millisecond
  */

  oCreate:destroy()
  oAccess:destroy()
  oWrite:destroy()

RETURN