只处理新文件 [英] process the new files only

查看:39
本文介绍了只处理新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要处理文件的来源.多个文件随时随机到达该位置(包应每 2 小时运行一次).我只需要处理新文件,我不能删除,从那个位置移动已经处理的文件.我只能将文件复制到存档位置.我怎样才能做到这一点?

I have a source from which the files are to be processed. Multiple files are coming to that loacation at any time randomly (Package should run every 2 hours). I have to process only the new files, i can not delete, move the already processed files from that location. I can only copy the files to Archive location. How can I achieve this ?

推荐答案

您可以使用以下步骤实现此目的.

You can achieve this using the following steps.

  1. 对传入文件夹使用 foreach 文件枚举器并保存IncomingFile"变量中的文件名.配置选择名称和扩展[在我的代码中我已经使用了,否则你需要做对脚本的一些修改]
  2. 创建两个 SSIS 变量,如ArchivePath"作为字符串和IsLoaded"为布尔值[默认为 false].
  3. 创建 SSIS 脚本组件并使用IncomingFile"和ArchivePath"作为只读变量.IsLoaded"应该是读写变量.
  4. 在脚本组件中编写以下代码.如果文件已经存在那么它将返回true.否则为假.

  1. Use the foreach file enumerator for your incoming folder and save the filename in "IncomingFile" variable. Configure to select "Name and Extension"[In my code I have used that otherwise you need to do some modification to the script]
  2. Create tow SSIS variables Like "ArchivePath" as string and "IsLoaded" as Boolean[default to false].
  3. Create the SSIS script component and use "IncomingFile" and "ArchivePath" as the readonly variable. "IsLoaded" should be the ReadandWrite variable.
  4. Write the following code in the script component. If file is already exists then it will return true. Otherwise False.

public void Main()
{
    var archivePath = Dts.Variables["ArchivePath"].Value.ToString();
    var incomingFile = Dts.Variables["IncomingFile"].Value.ToString();

    var fileFullPath = string.Format(@"{0}\{1}",archivePath,incomingFile);

    bool isLoaded = File.Exists(fileFullPath);

    Dts.Variables["IsLoaded"].Value = isLoaded;

    Dts.TaskResult = (int)ScriptResults.Success;
}

  • 使用优先约束来调用数据流任务,求值操作应该是表达式".在您的表达式框中设置如下内容.

  • Use the Precedence constraint to call the Data flow task and evaluation operation should be "Expression" . Set something as follows in your expression box.

    @IsLoaded==False

    希望这会有所帮助.

    这篇关于只处理新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆