我想检查文件是否存在于 SSIS 的特定文件夹中。我怎样才能做到这一点?
问问题
75171 次
4 回答
10
变量:
文件夹 - 字符串 - C::\Temp\
文件 - 字符串 - 1.txt
fileExists - 布尔值 - 假
public void Main()
{
string folder = Dts.Variables["User::folder"].Value.ToString(); //@"C:\temp\";
string file = Dts.Variables["User::file"].Value.ToString(); //"a.txt";
string fullPath = string.Format(@"{0}\{1}", folder, file);
Dts.Variables["User::fileExists"].Value = File.Exists(fullPath);
Dts.TaskResult = (int)ScriptResults.Success;
}
于 2013-07-10T14:49:10.847 回答
6
您可以使用Foreach Loop Container
并简单地将所有物品放入其中。如果文件存在则执行,不存在则不执行。很简单 :)
于 2015-04-01T13:47:28.253 回答
3
As an alternative to having an "out" variable, you could also Change the Dts.TaskResult
based on whether or not the file exists. The snippet below fails the script task if the file doesn't exist. (It also creates a log entry if logging is enabled.)
public void Main()
{
string fileName = Dts.Variables["User::sourcePath"].Value.ToString() + Dts.Variables["User::fileName"].Value.ToString();
if (File.Exists(fileName))
{
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.Log(string.Format("File {0} was not found.",fileName),0,null);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
于 2014-10-09T14:34:26.207 回答
1
SSIS 中没有可以执行此检查的本机任务,但您可以使用脚本任务完成此操作,但我建议您检查以下链接以了解实现此操作所需的简单步骤。
http://www.bidn.com/blogs/DevinKnight/ssis/76/does-file-exist-check-in-ssis
于 2013-07-10T12:26:23.033 回答