Sign in to follow this  
Followers 0
GEOSoft

File Dates

2 posts in this topic

I have to check a files date and if it is older than 30 days, pop up a message box. What is the best approach to take?


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is certainly not best, but until someone comes up with a better one. :whistle: +- one day

$time = FileGetTime("test.au3")
$moncalc=StringSplit("31,28,31,30,31,30,31,31,30,31,30,31",",") 
;$time[0] = year
;$time[1] = month
;$time[2] = day
$mon=0
For $i=1 To @MON
    $mon=$mon+$moncalc[$i]
Next
For $i=1 To $time[1]
    $mon=$mon-$moncalc[$i]
Next
$Timedif=(((@YEAR-$time[0])*365)+($mon)+@mday-$time[2])
MsgBox(1,"Date was "&$time[1]&"/"&$time[2]&"/"&$time[0],$timedif & " Days old")

There is not a lot of data calculation functions, so I used an array to give how many days in each month, added them, added 365 for each year change, and the difference in Days.

It doesn't work on leap years, like this one, and I didnt' calculate for time, 24hours=1day.

for a function you could do:

Func timedif($x)
$time = FileGetTime($x)
$moncalc=StringSplit("31,28,31,30,31,30,31,31,30,31,30,31",",") 
if IsArray ( $time) then
$mon=0
For $i=1 To @MON
    $mon=$mon+$moncalc[$i]
Next
For $i=1 To $time[1]
    $mon=$mon-$moncalc[$i]
Next
$Timedif=(((@YEAR-$time[0])*365)+($mon)+@mday-$time[2])
return $Timedif
else
msgbox(1,"Error","File not found")
endif
Endfunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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  
Followers 0