Sign in to follow this  
Followers 0
JoshG

Delete old Files

4 posts in this topic

Hi hoping i might get some help on this... I'm looking for a way to delete files by date i.e. delete any files older then a specified date or number of days older then system date files older then 120 days... within a specific folder and with specific file type

Thanks in advam\nce

Share this post


Link to post
Share on other sites



I haven't tested this, but it should do what you want.

To test it, I would change FileDelete to something else, maybe write the files to a text file or something so you can check and make sure it works correctly before actually deleting files.

Also, you will have to put your own path in.

#include <Date.au3>
#Include <File.au3>

    $files = _FileListToArray("Your path here", "*.ext", 2) ;create an array of files in the specified folder
    $date=@YEAR&"/"&@MON&"/"&@MDAY;getting the current date
    $newdate=_DateAdd("D",-120,$date) ;adding -120 days (subtract 120 days)
    $formatdate=StringSplit($newdate,"/") ;removing the /
    $newdate=$formatdate[1]&$formatdate[2]&$formatdate[3]&@HOUR&@MIN&@SEC ;putting the date back together in a format easily compared to the FileGetTime func
    If IsArray($files) Then ;Making sure an array was created
        For $i = 1 To UBound($files) - 1 ;Loop through all the files found
            $aTime = FileGetTime("Your path here" & $files[$i], 1, 1) ;get the creation time of the file
            If $aTime < $newdate Then ;check to see if creation time is older than 120 days
                FileDelete($files[$i]) ;delete the file if it is
            EndIf
        Next
    EndIf

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I actually answered your question in your PREVIOUS TOPIC OF THE SAME NAME

Look

Edited by Varian

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