Skip to content
⌘ NSIS Forum Archive

Time difference between two files - ${FileTimeDiff}

3 posts

Lloigor#

Time difference between two files - ${FileTimeDiff}

I thought maybe this can be useful to some.. works great for me.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Get the difference between two file times
;; P1 :i: File name A.
;; P2 :i: File name B.
;; P3 :o: Number of seconds between the two files, can be negative of positive
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!define FileTimeDiff "!insertmacro _FileTimeDiff"
!macro _FileTimeDiff _File1_ _File2_ _Diff_
   Push $0  ;; File Search Handle / File Time (UTC) (100 ns unit, 64bit int)
   Push $3  ;; File Info (struct) / File-2 Time (UTC) (Seconds)
   Push $4  ;; File-1 Time (UTC) (Seconds)
   System::Call '*(i, l, l, l, i, i, i, i, &t260, &t14) i .r3'  ;; Create WIN32_FIND_DATA Struct
   !insertmacro ___FileTimeUTCSeconds "${_File1_}"  ;; Get File1 UTC Time in Seconds
   Pop $4
   !insertmacro ___FileTimeUTCSeconds "${_File2_}"  ;; Get File2 UTC Time in Seconds
   Pop $3
   System::Int64Op $4 - $3                          ;; Calculate File Time Difference
   Pop $0
   _ftdexit:
   Pop $4
   Pop $3
   Exch $0
   Pop ${_Diff_}
!macroend
!macro ___FileTimeUTCSeconds _File_
   System::Call 'kernel32::FindFirstFileA(t, i) i("${_File_}", r3) .r0'  ;; Find file info
   IntCmp $0 -1 0 0 +4  ;; if handle <= -1 : not ok
      Push ""
      Pop $0
      Goto _ftdexit     ;; do not even check the other file
;; Else (valid handle)
      System::Call 'kernel32::FindClose(i) i(r0)'  ;; Close file search
      System::Call '*$3(i, l, l, l, i, i, i, i, &t260, &t14) i (,,, .r0)'  ;; Get File time
      System::Int64Op $0 / 10000000  ;; Conversion From '100 ns' >TO> '1 sec' unit
!macroend
; 
ex.: ${FileTimeDiff} "${SAVEDIR}\${FILETOCHECK}" "${BKPDIR}${BKPNUM}\${FILETOCHECK}" $0


Just began nsis scripting about a month ago, so feel free to suggest a better coding for this. 😉
.
T.Slappy#
Nice work!
Maybe you could add new parameter where user could choose which times to compare?
Example:
1: ftCreationTime;
2: ftLastAccessTime;
3: ftLastWriteTime;

Do not forget to add this article to wiki! 🙂