从文件名中提取子字符串并将其保存到 SSIS 中的变量 [英] Extracting substring from a filename and saving it to a variable in SSIS
问题描述
我无法提取文件名并将其保存到 SSIS 中的变量中.当且仅当它与 VIn 中的正则表达式中的模式匹配时,我才尝试保存文件名的子字符串.
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.
例如:
EIRSRequest_INC9999999.csv//这应该提取INC9999999并将其保存到VIn变量
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;
}
推荐答案
要更新 SSIS 脚本任务变量,该变量应设置为读/写"变量.
For an SSIS Script task variable to be updated, the variable should be set up as 'Read/Write' variable.
将您的变量添加到 ReadWriteVariables 并检查.
Add your variable to ReadWriteVariables and check.
您应该能够看到官方 docs 以及.
You should be able to see the official docs as well.
由用户提供给包以进行读/写访问的现有变量的逗号分隔列表.
The comma-delimited list of existing variables made available to the package by the user for read/write access.
这篇关于从文件名中提取子字符串并将其保存到 SSIS 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!