如何从 SSIS 包内的路径中提取文件名? [英] How do I extract file name from a path within an SSIS package?

查看:53
本文介绍了如何从 SSIS 包内的路径中提取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 SSIS 从下面给定的路径中提取文件名:

I would like to know how to extract the file name using SSIS from the below given paths:

O:\SourceFiles\Primary\care\ALC121.csv
O:\SourceFiles\Primary\care\COPL119.csv

我想将名称和完整路径插入到一个表格中,如下所示:

I would like to insert the names and the full path into a table as shown below:

QueryName  FileName 
---------  ---------------------------------------
ALC121     O:\SourceFiles\Primary\care\ALC121.csv
COPL119    O:\SourceFiles\Primary\care\COPL119.csv

推荐答案

我假设完整的文件名来自文件的 ForEach Enumerator.然后似乎请求是将该字符串减少到仅基本文件名.有些人会使用表达式来让你到达那里,但我发现这是一种丑陋的方法.相反,我会使用脚本任务并利用 .NET 库中的功能.

I'm assuming that the full file names are coming in off the ForEach Enumerator for files. It seems the request then is to reduce that string down to just the base file name. Some folks will use expressions to get you there but I find that an ugly approach. Instead, I'd use a script task and take advantage of the functionality in the .NET library.

System.IO.Path.GetFileNameWithoutExtension

返回指定路径字符串的文件名,不带扩展名.

Returns the file name of the specified path string without the extension.

创建第二个变量,使用字符串类型调用它QueryName,并将其设置为脚本中的读/写变量.根据使用 FileName 值的方法调用的结果分配它的值.

Create a second variable, call it QueryName with a type of String and set it as a read/write variable in the script. Assign the value of it based on the results of that metchod call with the FileName value.

然后使用执行 SQL 任务将它们插入到您的表中.使用 ? 作为参数.

Then use an Execute SQL Task to insert them into your table. Use a ? as a parameter.

这篇关于如何从 SSIS 包内的路径中提取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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