提问人:Conrad Jagger 提问时间:11/2/2012 最后编辑:milivojeviCHConrad Jagger 更新时间:11/2/2012 访问量:9790
使用 SSIS 脚本任务枚举文件夹中的文件 [已关闭]
Enumerate files in a folder using SSIS Script Task [closed]
问:
有人可以展示如何使用SSIS中的脚本任务枚举给定文件夹中的文件吗?
答:
1赞
milivojeviCH
11/2/2012
#1
配置两个变量:只读字符串和读写对象以接收文件列表。User::download_path
User::files_to_process
public void Main()
{
bool fireAgain = true;
var filesToProcess = new System.Collections.ArrayList();
var filesInDirectory = new System.Collections.ArrayList();
var download_path = (String)Dts.Variables["User::download_path"].Value;
// Find for example all csv files in the directory which are having size > 0
var downloadedFiles = new DirectoryInfo(download_path).EnumerateFiles("*.csv",SearchOption.TopDirectoryOnly);
foreach (var f in downloadedFiles)
{
if (f.Length > 0)
filesInDirectory.Add(f.FullName);
}
Dts.Events.FireInformation(3, "Getting files in directory", downloadedFiles.Count().ToString() + " found.", "", 0, ref fireAgain);
// Report the file names into the SSIS Log:
foreach (var f in filesToProcess)
{
Dts.Events.FireInformation(3, f.ToString(), "Ready for processing", "", 0, ref fireAgain);
}
// Return them into the READWRITE object variable
Dts.Variables["User::files_to_process"].Value = filesInDirectory;
Dts.TaskResult = (int)ScriptResults.Success;
}
评论
0赞
Si8
4/10/2014
设置如何?
0赞
milivojeviCH
4/11/2014
哪种设置?在 SSIS 中,这只是一个脚本任务。
0赞
Si8
4/11/2014
我尝试添加脚本任务,但一直失败,所以我直接转到连接管理器的表达式并添加了一个目前运行良好的表达式。谢谢。
评论