SSIS,使用脚本任务计算文件夹中的文件,循环任务,直到文件数达到25

时间:2017-05-31 10:52:43

标签: ssis-2012 msbi

需要开发一个应该从ftp /文件夹中读取文件数的包。如果计数小于25,则保持循环,一旦计数达到25,则转到下一个任务。

我尝试的是:

我使用了一个脚本任务,创建了一些变量和变量有文件计数(成功)。我在优先约束中使用表达式来检查特定文件夹中的文件数是否为25.如果不是,它将不会转到另一个任务。我不能做的是保持脚本任务循环,直到文件计数变为25.我尝试使用每个循环,但无法得到低谷。请建议。

请看看这个。我有2个脚本任务。第一个计算并显示文件夹中的文件数。这是脚本。

enter code here


public void Main()
    {
        // TODO: Add your code here

            String FolderPath = 
Dts.Variables["User::FolderPath"].Value.ToString();
            string Prefix = 
Dts.Variables["User::prefix"].Value.ToString();
            Int32 FileCnt = 0;
            var directory = new DirectoryInfo(FolderPath);
            FileInfo[] files = directory.GetFiles(Prefix + "*");
            //Declare and initilize variables            
            //Get one Book(Excel file at a time)
            foreach (FileInfo file in files)
            {
                FileCnt += 1;
                MessageBox.Show(file.Name);
            }
            MessageBox.Show(FileCnt.ToString());
            Dts.Variables["User::FileCnt"].Value = 
Convert.ToInt32(FileCnt);
    }

    #region ScriptResults declaration
    /// <summary>
    /// This enum provides a convenient shorthand within the scope of 
this class for setting the
    /// result of the script.
    /// 
    /// This code was generated automatically.
    /// </summary>
    enum ScriptResults
    {
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
    #endregion

}
} 

然后我编辑了优先约束并编写了表达式@FileCnt == 25,这意味着下一个脚本任务只会在文件夹中的文件数为25时执行。我现在想要的是第一个脚本任务应该在循环中运行,直到该文件夹​​获得25个文件。我想我们需要在这里使用foreachloop容器。你有没有得到我现在正在寻找的东西??

0 个答案:

没有答案
相关问题