Sometimes we need to use wildcard characters in ours SSIS solutions to define a search pattern. The SSIS has total support to wildcard, and you can keep using it to find files in a local file system, but how can we use it in a C# script for an FTP directory? The best way that I have found was using regex.
//Converting FilePattern to regex language
Regex mask = new Regex(‘^’ + Dts.Variables[“FilePattern“].Value.ToString().Replace(“.”, “[.]“).Replace(“*”, “.*”).Replace(“?”, “.”) + ‘$’, RegexOptions.IgnoreCase);
The FilePattern is my variable with the file name pattern.
- FileParttern [wildcard characters]: FinancialsData*.xlsx
- FileParttner [Regex]: ^FinancialsData.*[.]xlsx$
You can use the regex tester (http://regexstorm.net/) to check your pattern.