SSIS:从文件夹导入MAX(文件名) [英] SSIS: import MAX(filename) from folder

查看:153
本文介绍了SSIS:从文件夹导入MAX(文件名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 \\\Share\Folder\ 中选择一个 .csv 文件带有最大文件名,以便进一步导入到SQL。文件名是字母数字,例如 ABC_DE_FGHIJKL_MNO_PQRST_U-1234567.csv ,其中数字部分会有所不同,但每次运行包时我只需要一个最大值。

I need to pick one .csv file from \\\Share\Folder\ with max filename for further import to SQL. File name is alphanumerical, e.g. ABC_DE_FGHIJKL_MNO_PQRST_U-1234567.csv, where numerical part will vary, but I need the only max one each time the package runs.

约束:该SQL服务器上没有写访问权限,我使用## Temp表进行导入,这是文件名处理中最不希望使用的方法(此服务器上的每个循环都没有)。

Constraints: no write access on that SQL server, I use ##Temp table for import and this is the least desirable method for filename processing (no for each loops on this server).

理想情况下,它将是基于函数/表达式的变量(如果需要,可与脚本任务结合使用)传递给连接管理器。任何想法都值得赞赏。

Ideally it will be function/expr-based variable (combined with script task if needed) to pass into connection manager. Any ideas much appreciated.

推荐答案

使用脚本任务




  • 添加类型为String User :: CsvFile
  • 的变量
  • 将脚本任务添加到项目中,并将创建的变量添加为 ReadWriteVariable

  • Use a Script Task

    • Add a variable of type String User::CsvFile
    • Add a script task to your project and add your created variable as a ReadWriteVariable

      • 在脚本任务中,编写以下代码(VB.NET)

      • In Your Script task write the following code (VB.NET):

      您必须导入 System.Linq

      Public Sub Main()
      
          Dim strDirectory As String = "C:\New Folder" ' Enter =the directory
          Dim strFile As String = String.Empty
      
          strFile = IO.Directory.GetFiles(strDirectory, "*.csv", IO.SearchOption.TopDirectoryOnly).OrderBy(Function(x) x.Length).Last
      
      
          Dts.Variables.Item("CsvFile").Value = strFile
      
          Dts.TaskResult = ScriptResults.Success
      
      End Sub
      




      • 然后使用平面文件源中的此变量

      • 这篇关于SSIS:从文件夹导入MAX(文件名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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