Jump to content
Sign in to follow this  
rasim

Compare two files for modified date diff

Recommended Posts

Hello! How can compare two files for know what file is newest? I make below script:

#include <Date.au3>

$FileTime1 = FileGetTime(@ProgramFilesDir & "\Eset\updfiles\upd.ver")
$FileTime2 = FileGetTime("f:\base\updfiles\upd.ver")

$FullDate1 = DateFormat($FileTime1, "/")
$FullDate2 = DateFormat($FileTime2, "/")

If _DateDiff("n", $FullDate1, $FullDate2) < 1 Then
    MsgBox(0, "", "File " & @ProgramFilesDir & "\Eset\updfiles\upd.ver newest than f:\base\updfiles\upd.ver")
EndIf

Func DateFormat($sTimeArray, $Delim = "/")
    Local $retTime
    For $i = 0 To UBound($sTimeArray) -1
        If $i = 2 Then
            $retTime &= $sTimeArray[$i] & " "
            $Delim = ":"
        Else
            $retTime &= $sTimeArray[$i] & $Delim
        EndIf
    Next
    Return StringTrimRight($retTime, 1)
EndFunc

but mayb someone have other nice variant? :)

Thanks!

Share this post


Link to post
Share on other sites

Hi,

Maybe easier?..

; getnewest.au3
#include <Date.au3>
$sFile1=@ScriptDir&"\array.au3"
$sFile2=@ProgramFilesDir&"\AutoIt3\Include\array.au3"

$FileTime1 = FileGetTime($sFile1, 0, 1)
$FileTime2 = FileGetTime($sFile2, 0, 1)

If $FileTime1>$FileTime2 Then
    MsgBox(0, "", "File " & $sFile1&" newest than "&$sFile2&@LF&"File " & $FileTime1&" newest than "&$FileTime2&@LF)
EndIf

best, Randall

Share this post


Link to post
Share on other sites

Hi,

Maybe easier?..

; getnewest.au3
#include <Date.au3>
$sFile1=@ScriptDir&"\array.au3"
$sFile2=@ProgramFilesDir&"\AutoIt3\Include\array.au3"

$FileTime1 = FileGetTime($sFile1, 0, 1)
$FileTime2 = FileGetTime($sFile2, 0, 1)

If $FileTime1>$FileTime2 Then
    MsgBox(0, "", "File " & $sFile1&" newest than "&$sFile2&@LF&"File " & $FileTime1&" newest than "&$FileTime2&@LF)
EndIf

best, Randall

What? :) This is work correct? Are you sure?

P.S.

If your solution works correct, that is nice and easy variant :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...