Delete files older than 3 days using SSIS tasks

I want to delete all files in a given folder that are older than 3 days from today's date.

I tried using a "Foreach Loop container" with a "File System" task inside it but found I couldn't access any file properties such as the file creation date. Am I using the wrong task for this job

TIA,

Barkingdog

P.S. History of the problem:

I used the sql 2005 Database maintenance program to setup our database backup jobs. One day I noticed that the free space on the drive where we keep the dumps had grown small. I found that we had at least 4 weeks of dumps in there, not the 3 days I wanted to keep! I looked but could not find the "delete file" option in the SSIS package generated by the Database Maintenance Wizard. No wonder the files were piling up.



Answer this question

Delete files older than 3 days using SSIS tasks

  • WinForms

    KirkHaselden wrote:
    You da man!

    Did you vote

    -J



  • amendez

    You da man!

  • Shauliz

    if i'm not mistaken, you need to use either a script task or custom task...

  • blackghost

    If you need a feature then request it at Microsoft Connect.

    -Jamie



  • wpf michelle

    Would be a great addition to the file enumerator. Basically provide for more robust and flexible enumeration by date, file attributes etc. I don't think I'm the only one to have thought of this. Certainly useful.

    Kirk Haselden
    Author "SQL Server Integration Services"



  • Michael_Shao

    Good idea. For now I just used this script in a Script task

    ...

    Dim fi As System.IO.FileSystemInfo
    fi = My.Computer.FileSystem.GetFileInfo("c:\temp.txt")

    If (Now.DayOfYear - fi.CreationTime.DayOfYear) > 3 Then
    'fi.Delete()
    End If


  • Slyke

    Yes, that's what I finally did, thank you. BUT I am surprised that this feature -- which was in sql 2000, is apparently missing from the Mantenance plan in sql 2005. This is a ridiculous shortcoming, unless one likes old backups to accumulate and take all free disk space!.

    Yelp, yelp, yelp ............ ;)

    Barkingdog


  • ZeroSerenity

    I will.

    Barkingdog


  • Juergen Lorenz

    KirkHaselden wrote:

    Would be a great addition to the file enumerator. Basically provide for more robust and flexible enumeration by date, file attributes etc. I don't think I'm the only one to have thought of this. Certainly useful.

    Kirk Haselden
    Author "SQL Server Integration Services"

    Way ahead of you ;)

    https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx FeedbackID=179264

    -Jamie



  • Delete files older than 3 days using SSIS tasks