Jump to content
Sign in to follow this  

Delete old Files

Recommended Posts

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



My Android cat and mouse game

We're gonna need another Timmy!

Share this post

Link to post
Share on other sites

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


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...