Jump to content

Recommended Posts

Posted

I've used AutoIT for a long time and find it extremely user friendly. I've picked up tips and tricks from the forum and wanted to post a solution I just got hammered out. Nothing original as I copied most of the code from the help file. It works great though. I left the Msgbox's in but commented out to keep it easy to troubleshoot.

; ----------------------------------------------------------------------------

; Script Start

; ----------------------------------------------------------------------------

$CurrentDirectory = FileChangeDir("E:\DWC\EDI\EDI File Archive") ; Changes the current working directory to the one needed

; MsgBox(0, "", "Current Working Directory: " & @WORKINGDIR) ; Used for viewing the output of variable

#include <Date.au3> ; Using the Date.au3 file for reference library.

$TodaysDateIs = (@YEAR & "/" & @MON & "/" & @MDAY) ; Sets up the date format for calculation, must use Year, month, day format

; MsgBox(0, "", "The Date is: " & $TodaysDateIs ) ; Used for viewing the output of variable

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.

$search = FileFindFirstFile("*")

; Check if the search was successful

If $search = -1 Then

; MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

If $file = "." Then ContinueLoop ; Blocks output of the root directory "."

If $file = ".." Then ContinueLoop ; Blocks output of the current directory ".."

$FileDate = FileGetTime($file, 0, 0)

; MsgBox(0, "File Date is: ", $FileDate)

; MsgBox(0, "File Name is: ", $file)

If Not @error then

$yyyymmdd = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]

; MsgBox(0, "File Date is", $yyyymmdd)

EndIf

$DateDiffTotal = _DateDiff( 'D',$yyyymmdd,$TodaysDateIs)

; MsgBox(0, "", "Difference in Days: " & $DateDiffTotal ) ; Used for viewing the output of variable

If $DateDiffTotal > 31 Then

; MsgBox(0, "", $file & " is " & $DateDiffTotal & " days old and will be DELETED")

FileDelete($file) ; Actual delete statement.

Else

; MsgBox(0, "", $file & " is " & $DateDiffTotal & " days old and will be retained")

EndIf

WEnd

; Close the search handle

FileClose($search)

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...