Set file creation time

170 views
Skip to first unread message

Attila Szabó

unread,
Oct 22, 2025, 3:20:04 AM (9 days ago) Oct 22
to Harbour Users
Hi!

How can I set the creation, modification, and access time of a given file to a specified value?

Best regards,
Attila Szabo

Auge & Ohr

unread,
Oct 22, 2025, 6:43:07 AM (9 days ago) Oct 22
to Harbour Users
hi,

first you need to use  FILETIME-Struktur to create right FileTime.

FUNCTION FileTime(dDate, cTime)                  // API FileTime
LOCAL cConvertTime, cFileTime:=Space(8)

  IF dDate==NIL .AND. cTime==NIL
    DllCall("Kernel32.dll",DLL_STDCALL,"GetSystemTimeAsFileTime", @cFileTime)
    RETURN cFileTime
  ENDIF

  dDate:=IF(dDate=NIL,Date(),dDate)
  cTime:=IF(cTime=NIL,Time(),cTime)

  cConvertTime := w2Bin(Year(dDate))+;
                  w2Bin(Month(dDate))+;
                  w2Bin(0)+;
                  w2Bin(Day(dDate))+;
                  w2Bin(THours(cTime))+;
                  w2Bin(TMins(cTime))+;
                  w2Bin(TSecs(cTime))+;
                  w2Bin(0)
  IF DllCall("Kernel32.dll",DLL_STDCALL,"SystemTimeToFileTime", cConvertTime, @cFileTime)==0
    RETURN Space(8)
  ENDIF

RETURN cFileTime


than you need to use API  SetFileTime function

FUNCTION SetFileTime(cFile, aTime)               // API SetFileTime
LOCAL cCreation
LOCAL cAccess
LOCAL cWrite
LOCAL nKernel32Dll
LOCAL nH
LOCAL nPt := 0

   IF PCOUNT() = 2
      cCreation := aTime[1]
      cAccess   := aTime[2]
      cWrite    := aTime[3]

      nKernel32Dll:=DllLoad("Kernel32.dll")
      nH := FOPEN(cFile, FO_WRITE+FO_SHARED )
      If nKernel32Dll > 0 .AND. nH # -1
         nPt := DllCall(nKernel32Dll, DLL_STDCALL, 'SetFileTime', nH, @cCreation, @cAccess, @cWrite)
         DllUnload(nKernel32Dll)
      EndIf

      IF nH # -1
         FCLOSE(nH)
      ENDIF
   ENDIF

   IF nPt = 0
      ALERT( FormatErrorMessage( nPt ) )
   ENDIF

RETURN NIL

Jim

Hurricane

unread,
Oct 22, 2025, 12:30:38 PM (8 days ago) Oct 22
to harbou...@googlegroups.com
Hi,

examples with the Harbour function

Regards,
Hurricane


Auge & Ohr

unread,
Oct 23, 2025, 12:10:30 AM (8 days ago) Oct 23
to Harbour Users
hi,
in HMG there is a Function SetFileDateTime(cFile, dDate, cTime )
in Fivewin look at  files.c for HB_FUNC( SETFTIME )

Jim

Attila Szabó

unread,
Oct 24, 2025, 8:40:05 AM (6 days ago) Oct 24
to Harbour Users
Hi,
Thank you everyone for your help.
Attila

Reply all
Reply to author
Forward
0 new messages