SSIS 2005 Delete a File in a Directory

  • The file name is 000_FILE001_yyyymmdd.csv. Each day the package runs, the yyyymmdd changes. the file path is on a server and it is \\server\product\application\ssis\outbound\00\.

    I want to avoid having a human go to the location and delete the files on a daily basis. I would like the first task of the SSIS package to simply find ALL files in that directory that end *.csv and DELETE them...ALL. The file name will never change except for the date. So I really dont care how I go about the deletion, I just want it simple. It can be VB.net, Foreach Loop Container, etc. Whatever is simple. Please and thank you...

    I have tried this article, but the expression test screams at me because it can't convert DT_WSTR to DT_DATE.

    http://beyondrelational.com/modules/2/blogs/106/posts/11114/ssis-delete-files-in-a-folder-older-than-a-specified-number-of-days.aspx

  • I figured it out...

    Public Class ScriptMain

    Public Sub Main()

    For Each file As IO.FileInfo In New IO.DirectoryInfo("\\server\...").GetFiles

    If file.Extension.Equals(".csv") AndAlso (Now - file.CreationTime).Days >= 0 Then file.Delete()

    Next

    End Sub

    End Class

    I added this (Days >= 0) to delete everything today. Obviously I'll change it to > 1 in production.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply