Old 17th October 2011, 21:59   #1
Junior Member
Join Date: Oct 2011
Posts: 9
Thumbs up Time difference between two files - ${FileTimeDiff}

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

PHP Code:
Get the difference between two file times
;; P1 :iFile name A.
P2 :iFile name B.
P3 :oNumber of seconds between the two filescan be negative of positive
define FileTimeDiff "!insertmacro _FileTimeDiff"
!macro _FileTimeDiff _File1_ _File2_ _Diff_
$0  ;; File Search Handle File Time (UTC) (100 ns unit64bit 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
!insertmacro ___FileTimeUTCSeconds "${_File2_}"  ;; Get File2 UTC Time in Seconds
::Int64Op $- $3                          ;; Calculate File Time Difference

Pop $4
!macro ___FileTimeUTCSeconds _File_
::Call 'kernel32::FindFirstFileA(t, i) i("${_File_}", r3) .r0'  ;; Find file info
$-1 0 0 +4  ;; if handle <= -not ok
Pop $0
Goto _ftdexit     ;; do not even check the other file
;; Else (valid handle)
System::Call 'kernel32::FindClose(i) i(r0)'  ;; Close file search

::Call '*$3(i, l, l, l, i, i, i, i, &t260, &t14) i (,,, .r0)'  ;; Get File time
::Int64Op $10000000  ;; Conversion From '100 ns' >TO'1 sec' unit


Just began nsis scripting about a month ago, so feel free to suggest a better coding for this.
Lloigor is offline   Reply With Quote
Old 18th October 2011, 06:20   #2
Major Dude
T.Slappy's Avatar
Join Date: Jan 2006
Location: Slovakia
Posts: 540
Send a message via ICQ to T.Slappy
Nice work!
Maybe you could add new parameter where user could choose which times to compare?
1: ftCreationTime;
2: ftLastAccessTime;
3: ftLastWriteTime;

Do not forget to add this article to wiki!

Cool looking installers with custom design: www.graphical-installer.com
Design NSIS setup Pages easily: www.install-designer.com
Build NSIS installers in Visual Studio 2005-2019: www.visual-installer.com
or RAD Studio 2009, 2010, XE-10.3 Rio: www.rad-installer.com
T.Slappy is offline   Reply With Quote
Old 20th October 2011, 19:09   #3
Junior Member
Join Date: Oct 2011
Posts: 9
Also made it 3-modes.
Lloigor is offline   Reply With Quote
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

difference, file, filetimediff, seconds, time

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump