Recently I needed to get a list of subfolders in SSIS. I also only wanted to bring back a list of subfolders that had the date appended to the end. So let’s walk through how to do this in Script Task using c#.
First we need to create two variables in SSIS:
Next bring a script task into the control flow and open it up for editing.
- Select C# for the script language.
- ReadWriteVariables select objDirectoryList
Now select Edit Script
- Under the section “public void Main()” enter the following code:
- Of course replace the directory location with your directory.
Dts.Variables["objDirectoryList"].Value = System.IO.Directory.GetDirectories(@"C:\Blogs\RootFolder\","*20*",AllDirectories); Dts.TaskResult = (int)ScriptResults.Success; } public SearchOption AllDirectories { get; set; }
Essentially all I’m doing here is populating the object variable objDirectoryList with all the subdirectories in the folder C:\Blogs\RootFolder\. Notice that I have also added a filter here “*20*”. If you do not wish to have a filter and you want to bring back all subdirectories then just replace my filter with “*”.
Finally we can now iterate through this object variable in a FELC.
Below you can see the two directories that are returned from the script task above.
Thanks for looking, hope this helps.