Jump to content
Sign in to follow this  
vcent

Compare two files with date

Recommended Posts

vcent

I need to compare files with dates and pick the latest one.

I already have an array of files. But is there any function that can compare dates ?

I'm thinking of using _Date_Time_GetFileTime to get the array files.

But wondering how do you go about comparing them.

tks.

Share this post


Link to post
Share on other sites
Malkey

I need to compare files with dates and pick the latest one.

I already have an array of files. But is there any function that can compare dates ?

I'm thinking of using _Date_Time_GetFileTime to get the array files.

But wondering how do you go about comparing them.

tks.

You could have a look at this function, it may help.

#include <Date.au3>

Local $file1 = "temp-6.au3"
Local $file2 = "temp-51.au3"
Local $LatestFile

$LatestFile = FileLatest($file1, $file2)

MsgBox(4096, "", "Newest Date: " & $LatestFile & @CRLF)

; $opt - [optional] Flag to indicate which timestamp
;       0 = Modified (default)
;       1 = Created
;       2 = Accessed
Func FileLatest($file2, $file1, $opt = 0)
    Local $sNewest

    Local $t1 = StringRegExpReplace(FileGetTime($file1, $opt, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "\1/\2/\3 \4:\5:\6")
    Local $t2 = StringRegExpReplace(FileGetTime($file2, $opt, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "\1/\2/\3 \4:\5:\6")
    ConsoleWrite($file1 & " date = " & $t1 & "  " & $file2 & " date = " & $t2 & @CRLF)
    If _DateDiff('s', $t1, $t2) < 0 Then
        $sNewest = $file1
    Else
        $sNewest = $file2
    EndIf
    Return $sNewest
EndFunc  ;==>FileLatest

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.