Jump to content

Searching Files older than 3 hours?


Recommended Posts

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.

Link to comment
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

Link to comment
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

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

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
Link to comment
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

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...