I needed a way to clean up old folders and files in the folders using SSIS. The foreach loops just were not working to do what I thought was a simple task. So I went to using a script object and works exactly how I need it to. My process will rebuild the folders each day, but I wanted to make sure if some data is not needed it is removed, as a final step just look through all the folders and creates a self-extracting zip file of the contents and I do not want to waste resources with old data.
public void Main() string[] folders = System.IO.Directory.GetDirectories(Dts.Variables["BaseOutputFolder"].Value.ToString()); foreach(var folder in folders) { System.IO.Directory.Delete(folder, true); } Dts.TaskResult = (int)ScriptResults.Success; }