A question I quite often see on the SSIS forum is:
Is there a way to delete a group of files within a directory? ie: I want to delete all files in directorty c:\logs\*.txt
(http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3196521&SiteID=1)
Well its actually quite easy, you just need ForEach Loop container and the FileSystem Task. Here's how you set up the ForEach Loop container:
In the 'Collection' tab you need to specify the enumerator, the folder from which to delete, and a fie mask to specify the files that you want to delete.
In the Variable Mappings tab you need to store the enumerated filename in a pre-created variable. The index will be 0 in this case because we are only interested in the file name which gets returned in the first column of the zero-based enumeration.
After that we have the simple task of wiring up the File System task that we do like so:
Note that we have used the variable "[User::FileName] that we populated using the ForEach Lloop container.
And that is pretty much it. Very simple indeed when you know how. I have made a demo package available here:
-Jamie