Search code examples
sql-serverssisssis-2014

SSIS Foreach loop through text files with "crosswlk" in the name


In my Foreach loop I only want to process files that have crosswlk in the filename. Unfortunately this is in the middle of the filename and I can't do crosswlk.pgp.

I have Googled this a bunch and most solutions say to do some C# in a script task to accomplish this. It seems like I should be able to do this in the Foreach container, maybe in the Collection area with Expressions. But I'm having troubles finding any information about the various Properties in the Property Expressions Editor. What's the difference between the Name, FileSpec and FileNameRetrieval properties?

I thought I could do something like:

Property: Name
Expression: `FINDSTRING(@[User::SourceFilename],"crosswlk",1) > 0`

To me that's saying only process files where the filename has crosswlk in it. But that's not working. I did notice the word crosswlk always starts at the 13th character in the filename so I tried using substring, but no luck there either.

Is there a way to do filter the filenames this (or another) way, or is using C# the only way? Thanks very much!


Solution

  • According to the documentation, you should be able to use wildcards in the Files field.

    Use wildcard characters (*) to specify the files to include in the collection. For example, to include files with names that contain “abc”, use the following filter: *abc*.

    So, you should be able to use something like this: *crosswlk*

    See here for more detail: https://learn.microsoft.com/en-us/sql/integration-services/control-flow/foreach-loop-container#enumerator-dynamic-options