如何使用 SSIS 包中的 foreach 循环容器更改平面文件源? [英] How to change flat file source using foreach loop container in an SSIS package?

查看:36
本文介绍了如何使用 SSIS 包中的 foreach 循环容器更改平面文件源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SSIS 中使用 foreach 循环容器更改平面文件路径

How can i change Flat file path using foreach loop container in SSIS

我有一个位于 c:\sourcefile 下的平面文件,文件名是Flat(Date)"例如 Flat01aug2011.csv每天它都是由最近的日期生成的,所以我需要始终选择新文件并将其传递给平面文件目的地,那么我如何遍历文件夹并获取最近日期的新文件.???

I'm having flat file which is under c:\sourcefile name of the file is "Flat(Date)" for e.g Flat01aug2011.csv and every day it is generated by recent date so i need to picked up new file always and pass it to Flat File destination , so how can i traverse through folder and take new file which is having recent date.???

推荐答案

下面给定链接中的示例显示了如何循环遍历给定扩展名的文件并使用数据流任务将它们加载到数据库中.

Example in the below given link shows how you can loop through files of a given extension and load them into a database using Data Flow Task.

该示例加载 .csv 文件.该包使用Foreach 循环容器 来循环遍历文件,并且循环容器内有一个数据流任务.数据流任务包含一个平面文件源,它根据循环的文件而变化.这是通过更改平面文件连接管理器路径来完成的.

The example loads .csv files. The package uses a Foreach loop container to loop through the files and there is a Data Flow task within the loop container. The Data Flow task contains a Flat file source which changes based on the file being looped through. This is done by altering the Flat File Connection Manager path.

怎么做处理完文件后,我将文件移动到存档文件夹吗?

这是一个示例,它循环遍历给定目录中的目录列表,并使用脚本任务和 Foreach 循环容器选择最近创建的文件夹.您需要使用类似的逻辑来选择最近创建的文件.

Here is an example that loops through a list of directories within a given directory and picks the most recently created folder using Script Task and Foreach loop container. You need to make use of a similar logic to pick the most recently created file.

如何选择最近创建的在 SSIS 包中使用 Foreach 循环容器的文件夹?

希望有所帮助.

更新:

创建两个字符串数据类型变量,即DirPathFilePath.将值 C:\backup\ 设置为变量 DirPath.不要为变量 FilePath 设置任何值.

Create two string data type variables namely DirPath and FilePath. Set the value C:\backup\ to the variable DirPath. Do not set any value to the variable FilePath.

选择变量 FilePath 并选择 F4 以查看属性.将 EvaluateAsExpression 属性设置为 True 并将 Expression 属性设置为 @[User::DirPath] + "Source" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE()) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "-" + RIGHT("0" +(DT_STR, 2, 1252) DATEPART("dd", GETDATE()), 2)

Select the variable FilePath and select F4 to view the properties. Set the EvaluateAsExpression property to True and set the Expression property as @[User::DirPath] + "Source" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE()) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)

这篇关于如何使用 SSIS 包中的 foreach 循环容器更改平面文件源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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