I am not able to extract filename and save it to a variable in SSIS. I am trying to save a sub string of a filename if and only if it matches the pattern in regex in VIn.
For example:
EIRSRequest_INC9999999.csv //this should extract INC9999999 and save it to VIn variable
public void Main()
{
String source = @"F:";
//String destination = @"F:";
Regex regex = new Regex(@"EIRSRequest_(?<val>[a-zA-Z0-9]{1,})");
DirectoryInfo di = new DirectoryInfo(source);
//FileInfo fi = new FileInfo(di.GetFiles);
foreach (FileInfo fi in di.GetFiles())
{
var match = regex.Match(Path.GetFileNameWithoutExtension(fi.Name));
if (match.Success)
{
//Console.WriteLine(match.Groups["val"].Value);
Dts.Variables["User::vIn"].Value= match.Groups["val"].Value;
//Console.WriteLine(ticket);
//File.Move(source + "" + fi.Name, destination + "" + fi.Name);
//Console.WriteLine("This is a new line");
break;
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…