Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssis 将脚本任务中找到的文件复制到文件夹SSI_Ssis - Fatal编程技术网

Ssis 将脚本任务中找到的文件复制到文件夹SSI

Ssis 将脚本任务中找到的文件复制到文件夹SSI,ssis,Ssis,我刚开始编码,对ssis有一点了解,我可以帮助自己,但我被卡住了-我想每天用ssis脚本任务将最新的.gz文件从文件夹复制到我自己的文件夹,我能够用脚本识别最新的文件,但我被困在需要复制的地方 以下是我的脚本: public void Main() { // TODO: Add your code here var directory = new System.IO.DirectoryInfo(Dts.Variables["User::VarFolder

我刚开始编码,对ssis有一点了解,我可以帮助自己,但我被卡住了-我想每天用ssis脚本任务将最新的.gz文件从文件夹复制到我自己的文件夹,我能够用脚本识别最新的文件,但我被困在需要复制的地方

以下是我的脚本:

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

        var directory = new System.IO.DirectoryInfo(Dts.Variables["User::VarFolderPath"].Value.ToString());

        System.IO.FileInfo[] files = directory.GetFiles("DailyReport-*.gz");
        DateTime lastModified = DateTime.MinValue;

        foreach (System.IO.FileInfo file in files)
        {
            if (file.LastWriteTime > lastModified)
            {
                lastModified = file.LastWriteTime;
                Dts.Variables["User::VarFileName"].Value = file.ToString();
            }
        }

       // MessageBox.Show(Dts.Variables["User::VarFileName"].Value.ToString());



    }
}
}

它可以识别我在Foreach循环容器中运行的文件,但是当我添加文件系统任务时,它不会复制正确的文件

我已经为副本保存了变量 用户:DestinationFolder作为目标连接 用户:源文件夹作为源连接 以复制文件作为操作

在my User:SourceFolder变量中,我的值保存为我最初测试时使用的确切文件名,但在下次更新源文件夹时它发生了更改,现在复制任务会继续复制同一文件

该文件在每次更新时基本上都有相同的名称,例如,除了结尾

  • DailyReport-20180725050247.gz上午6:00 然后
  • DailyReport-20180725080801.gz,当天上午8:00
我想复制第二个或当天晚些时候更新的

我的变量:

  • SourceFolder-X:\FTP\In\DailyReport-20180725050247.gz
  • DestinationFolder-X:\MIS\u AUTO\Lizl\Test
  • VarFolderPath-X:\FTP\In
  • 变量文件名-

希望这有意义

我尝试用
脚本任务
文件系统任务
重新处理您的问题。 这里唯一需要更改的是实际通过的
User::VarFileName
。对于
文件系统任务
如果选择作为
源连接->IsSourcePathVariable
的变量,则需要传递完整的文件路径信息

所以,在脚本任务中,您需要这样-

Dts.Variables["User::VarFileName"].Value = file.FullName.ToString();

您的软件包还有其他功能吗?如果没有,只需在Powershell中编写