Jump to content

Recommended Posts

Posted

How to delete files from specified but only this files which are older than for example 30 days

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Plenty of Examples in the Forum to be honest :)

Modified this >Example.

#include <Date.au3> ; Required for _DateDiff()
#include <MsgBoxConstants.au3>
#include <MsgBoxConstants.au3>

; Check if the current script is older than 10 days.
If _IsFileOlder(@ScriptFullPath, 10) Then
    MsgBox($MB_SYSTEMMODAL, '', 'File is older than 10 days.')
Else
    MsgBox($MB_SYSTEMMODAL, '', 'File isn''t older than 10 days.')
EndIf

; Is a file older than a certain number of days.
Func _IsFileOlder($sFilePath, $iDays)
    Local Enum $FT_YEAR, $FT_MONTH, $FT_DAY, $FT_HOUR, $FT_MIN, $FT_SEC
    Local $aArray = FileGetTime($sFilePath, $FT_CREATED)
    Return ((@error > 0) ? Null : _DateDiff('D', $aArray[$FT_YEAR] & '/' & $aArray[$FT_MONTH] & '/' & $aArray[$FT_DAY] & ' ' & $aArray[$FT_HOUR] & ':' & $aArray[$FT_MIN] & ':' & $aArray[$FT_SEC], @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC) >= Int($iDays))
EndFunc   ;==>_IsFileOlder
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Or another way...

#include <Date.au3> ; Required for _DateDiff()

; Check if the current script is older than 10 days.
If _IsFileOlder(@ScriptFullPath, 10) Then
    MsgBox(4096, '', 'File is older than 10 days.')
Else
    MsgBox(4096, '', 'File isn''t older than 10 days.')
EndIf

; Is a file older than a certain number of days.
Func _IsFileOlder($sFilePath, $iDays)
    Local $aArray = FileGetTime($sFilePath, 0)
    Return _DateDiff('D', $aArray[0] & '/' & $aArray[1] & '/' & $aArray[2] & ' ' & $aArray[3] & ':' & $aArray[4] & ':' & $aArray[5], @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC) >= $iDays
EndFunc   ;==>_IsFileOlder
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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