1
votes

I try through SSIS to extract the names of the files contained within the folder names and load into a SQL Server table. The folders names are already stored in an SSIS package variable.

I'd like to use a Foreach Loop Container that (for each iteration);

1) Take one folder name (stored in the object variable) in input.
2) Read all the files names of the folder.
3) Load the files names to a SQL Server destination table.

Does anyone have a solution?

Thanks in advance.

2

2 Answers

0
votes

You said you have the directories in a object variable.

  1. Add a foreach loop (choose ADO Object) and set variable to a string variable called targetDirectory
  2. Add a data flow
  3. Add a script component source
  4. Add an output called fileName as type string
  5. Pass in variable targetDirectory as read
  6. Add the following code to CreateOuputRows

    foreach(string fName in System.IO.Directory.GetFiles(Variables.targetDirectory))
    {
       Output0Buffer.AddRow();
       Output0Buffer.fileName = fname;
    }
    
  7. Continue data flow to your destination.

Reference https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netframework-4.8

0
votes

My other answer is just fine and would be closer to the way I would do it completely in C#.

However, in SSIS you can do it with just objects provided:

enter image description here