SSIS Script Task Get File Names and Store to an SSIS Object Variable

后端 未结 1 732
半阙折子戏
半阙折子戏 2020-12-11 06:37

I am trying to build an SSIS package that will be used in a standardized file system archive process. Basically, I will be able to add information to a configuration table

相关标签:
1条回答
  • 2020-12-11 07:24

    Inside your script, just build an array of the file names and set that array to your variable (make sure the variable is set to writable in the scripting task). If the variable is of type object you can then iterate on it using a for loop in a subsequent task and do whatever you want to with the files. You should not need to work on any miracles solely in one script.

    Put all files under your source dir in an Array:

    string[] array1 = Directory.GetFiles(Dts.Variables("SourceNetworkFolderName").Value.ToString());
    

    Put all files with an extension of "BIN" in an array:

    string[] array2 = Directory.GetFiles(Dts.Variables("SourceNetworkFolderName").Value.ToString(), "*.BIN");
    

    You may need to include System.IO at the top of your scripting code.

    EDIT:

    To convert array to a List for processing by the Loop task. After calling the code above, call this:

    List<string> fileList = new List<string>(astrTest);
    Dts.Variables["SourceFilesInTheDirectory"].Value = fileList;
    

    You will need to include System.Collections.Generic at the top of your script file.

    0 讨论(0)
提交回复
热议问题