Jump to content
Sign in to follow this  
Cyri

Best way to see if file/folder creation is today?

Recommended Posts

Cyri

I'm trying to figure out the best way to see if a file/folder's creation date is today. This is what I'm currently using.

#include <Date.au3>
$aFileTime = FileGetTime(@WindowsDir, 1)
If StringCompare($aFileTime[0] & "/" & $aFileTime[1] & "/" & $aFileTime[2], _NowCalcDate()) = 0 Then
     MsgBox(0, "", "created today")
EndIf

Is there a better way than that? I played with _DateDiff() as well, but using days it was matching stuff that occured within the last 24 hours and not actually today.

Share this post


Link to post
Share on other sites
spudw2k

You could do this.

_CreatedToday(@WindowsDir)

Func _CreatedToday($varFileFolder)
    $aFileTime = FileGetTime($varFileFolder, 1)
    If $aFileTime[0]&$aFileTime[1]&$aFileTime[2] = @YEAR&@MON&@MDAY Then 
        MsgBox(0, $varFileFolder, "Created today.")
        Return 1
    EndIf
EndFunc

edit: made into func.

Edited by spudw2k

Share this post


Link to post
Share on other sites
Cyri

You could do this.

_CreatedToday(@WindowsDir)

Func _CreatedToday($varFileFolder)
    $aFileTime = FileGetTime($varFileFolder, 1)
    If $aFileTime[0]&$aFileTime[1]&$aFileTime[2] = @YEAR&@MON&@MDAY Then 
        MsgBox(0, $varFileFolder, "Created today.")
        Return 1
    EndIf
EndFunc

edit: made into func.

I got so hung up on trying to put the FileGetTime return back into a date format that I forgot I could just compare them using the built-in macros for year, month, and day. I like the function idea. Thanks.

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.