Jump to content
Sign in to follow this  
supadodger

_Nowdate and Filegettime

Recommended Posts

supadodger

$nowdate = _NowDate()

$t = FileGetTime(@Windowsdir & "\Notepad.exe", 1)

$yyyymd = $t[1] & "/" & $t[2] & "/" & $t[0]

if $nowdate => $yyymd + 30 Then

Share this post


Link to post
Share on other sites
SmOke_N

$nowdate = _NowDate()

$t = FileGetTime(@Windowsdir & "\Notepad.exe", 1)

$yyyymd = $t[1] & "/" & $t[2] & "/" & $t[0]

if $nowdate => $yyymd + 30 Then

Well that was a very well thought out and presented question :) .

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
supadodger

sorry about that.

im trying to verify a file creation date against the current date and delete the file if its older than 30 days.

i think i have the gist of it but its not working properly.

Share this post


Link to post
Share on other sites
pdaughe

sorry about that.

im trying to verify a file creation date against the current date and delete the file if its older than 30 days.

i think i have the gist of it but its not working properly.

This is based on last modification date, but easily change to use creation date:

;==============================================
;    File Age (minutes since last modified)
;==============================================
Func FileAge ($sFile)

Local $FileTime = FileGetTime ($sFile)
If @error Then Return SetError (-1, 0, -1)

;-----------------------------------------------------------------------------------
;    Get the difference in days between the current date and file date 
;-----------------------------------------------------------------------------------
Local $Days_Old = _DateToDayValue (@Year, @Mon, @MDAY) - _DateToDayValue ($FileTime[0], $FileTime[1], $FileTime[2])

;-----------------------------------------------------------------------------------
;    Get the difference in seconds between the current time and file time
;-----------------------------------------------------------------------------------
Local $FileTimeInSecs = $FileTime[3] * 3600 + $FileTime[4] * 60 + $FileTime[5], _
      $CurrentTimeInSecs = @Hour     * 3600 + @Min       * 60 + @SEC, _
      $Time_Difference_In_Seconds = $CurrentTimeInSecs - $FileTimeInSecs

If $Time_Difference_In_Seconds < 0 Then
   $Days_Old = $Days_Old - 1
   $Time_Difference_In_Seconds = $Time_Difference_In_Seconds + 24 * 60 * 60
EndIf

Return $Days_Old * 24 * 60 + Int ($Time_Difference_In_Seconds / 60)

EndFunc

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  

×