Sign in to follow this  
Followers 0
roman

Searching Files older than 3 hours?

7 posts in this topic

Hi

I'm (still) quite new with AutoIt and i wonder how i can recognize files with a specific age, e.g. all files older than 3 hours, or all files older than 5 days and so on (allways refering to atribute "modifyed")

How should i script this? :">

Thanks for every hint.

Roman.

Share this post


Link to post
Share on other sites



Not sure but it must be possible with ExtProp.au3 from Simucal.

Share this post


Link to post
Share on other sites

Hi,

FileGetTime() will be enough, I guess.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

For example:

Local $pattern = "*.*"
Local $file
Local $handle

$handle = FileFindFirstFile($pattern)
If $handle = -1 Then
   MsgBox(4096, "Error", "No Files found!")
   Exit
EndIf

$list=""
While 1
   $file = FileFindNextFile($handle)
   If @error Then ExitLoop
   
   If $file <> "." And $file <> ".." Then
      If Not StringInStr(FileGetAttrib($file), "D") Then; not a directory
          $time = FileGetTime($file,0,1)
          $now = @YEAR & @MON & @MDAY & (@HOUR-3) & @MIN & @SEC
          if $time < $now Then
              $list = $list & $file & @CRLF
          EndIf
      EndIf 
   EndIf
Wend
FileClose($handle)
MsgBox(0,"Files older 3 hours",$list)

have fun,

Marc


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For example:

...
...
          $now = @YEAR & @MON & @MDAY & (@HOUR-3) & @MIN & @SEC
...
...

have fun,

Marc

Thanks, but is "@HOUR-3" a good idea? E.g. if i have one a clock in the night, with "@HOUR-3" i get a "-2"

Then i get probably a non-numeric string within "$now" who cannot by compared with a number, or am i wrong?

I searched too and found the UDFs _DateAdd und _DateDiff; i think they could be a solution for me because the enable me to calculate dates and times. :D

Thanks,

Roman.

Edited by roman

Share this post


Link to post
Share on other sites

I think you don't need the two UDF's. '_DateDiff() ' and '_DateAdd ()' can you find in the 'User Defined Function - Date Management' in helpfile. You only have to include 'Date.au3'.

#include <Date.au3>

Briegel

Share this post


Link to post
Share on other sites

Thanks, but is "@HOUR-3" a good idea? E.g. if i have one a clock in the night, with "@HOUR-3" i get a "-2"

Then i get probably a non-numeric string within "$now" who cannot by compared with a number, or am i wrong?

Oops, forgot to mention it ... you're right of course. There has to be a check if the number gets negative, add +24 hours and step one day back (checking for "walking back a month this way" and even, on the 1st of January, changing back to the last year.)

So I'd suggest to use _dateAdd() instead :D


It's my job to comfort the disturbed and to disturb the comfortable.

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