如何仅将文件集移动到SSIS中的另一个目录 [英] How to move only set of files to another directory in SSIS

查看:38
本文介绍了如何仅将文件集移动到SSIS中的另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个包含10个文本文件的源目录,两个源目录如Destination1,Destination2.
10个文本文件名称:
1)Feed1
2)other7
3)Feed3
4)Feed4
5)Feed5
6)Feed6
7)Feed2
8)other8
9)other9
10)other10

现在我想将文件(名称为Feed * .txt)移动到Destination1目录,并将其余文件移动到Destination2目录.如何在SSIS中实现? >使用文件系统任务.但是,由于您要去两个不同的目的地,因此可能需要两个文件系统任务.我相信您一次只能移动一个文件.

因此,您可能需要一个ForEach循环容器.

请参阅此处: http://www.sqlservercentral.com/Forums/Topic508448-148-2.aspx #bm752592 [ ^ ]


使用foreach循环工具枚举每个文件,在循环内使用文件系统任务,然后再执行脚本任务.使用目标变量配置文件系统任务,此目标变量应来自脚本任务.脚本任务代码如下:
"
使用系统;
使用System.Data;
使用Microsoft.SqlServer.Dts.Runtime;
使用System.Windows.Forms;
使用System.IO;
命名空间ST_61a0f7e8968e4c2ba69c3e2dc24d3366.csproj
{
[System.AddIn.AddIn("ScriptMain",Version ="1.0",Publisher =",Description =")]
公共局部类ScriptMain:Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

#region VSTA生成的代码
枚举ScriptResults
{
成功= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
失败= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion

public void Main()
{
字符串feedname = Dts.Variables ["SourceFeed"].Value.ToString();
字符串DestPath = Dts.Variables ["DestinationPath"].Value.ToString();
字符串requiredfilanameformat =(Dts.Variables ["myformat"].Value.ToString()).ToUpper();
字符串FileName = Path.GetFileName(feedname);
FileName =(FileName.Substring(0,期望的filanameformat.Length)).ToUpper();
//System.Windows.Forms.MessageBox.Show(FileName);
如果(FileName.Equals(desiredfilanameformat))
{
Dts.Variables ["DestinationPath"].Value ="C:\\ destinationfolder";
}
其他
{
//System.Windows.Forms.MessageBox.Show(文件名:" +文件名+期望的文件名格式" +客户名);
Dts.Variables ["DestinationPath"].Value ="C:\\ destinationfolder2";
}
Dts.TaskResult =(int)ScriptResults.Success;
}
}
}"


hi,


I have one source directory with 10 text files, two source directories like namely Destination1, Destination2.
10 text files names:
1)Feed1
2)other7
3)Feed3
4)Feed4
5)Feed5
6)Feed6
7)Feed2
8)other8
9)other9
10)other10

now i want move files(with name Feed*.txt) to Destination1 directory, and move rest of files to Destination2 directory.How to achieve in SSIS???

解决方案

Use a File System Task. But since you are going to two different destinations you may need two File System Tasks. I believe you can only move one file at a time however.

So you may need a ForEach Loop Container.

See here: http://www.sqlservercentral.com/Forums/Topic508448-148-2.aspx#bm752592[^]


use foreach loop tool for enumerate each file, Use a File System Task inside the loop followed by script task. configure file system task with destination variable, this destination variable should come from script task. script task code as below:
"
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
namespace ST_61a0f7e8968e4c2ba69c3e2dc24d3366.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion

public void Main()
{
String feedname = Dts.Variables["SourceFeed"].Value.ToString();
String DestPath = Dts.Variables["DestinationPath"].Value.ToString();
String desiredfilanameformat= (Dts.Variables["myformat"].Value.ToString()).ToUpper();
String FileName = Path.GetFileName(feedname);
FileName = (FileName.Substring(0, desiredfilanameformat.Length)).ToUpper();
// System.Windows.Forms.MessageBox.Show(FileName);
if (FileName.Equals(desiredfilanameformat))
{
Dts.Variables["DestinationPath"].Value = "C:\\destinationfolder";
}
else
{
// System.Windows.Forms.MessageBox.Show("Filename:" + FileName + " desiredfilanameformat" + Customername);
Dts.Variables["DestinationPath"].Value = "C:\\destinationfolder2";
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}"


这篇关于如何仅将文件集移动到SSIS中的另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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