Conrad Jagger
Conrad Jagger

Reputation: 2333

SSIS Package - Looping through folder to check if files exists

Can anyone help:

Required: SSIS Package to loop through a folder (containing 100 files) and check whether required files (which are 5/6) are present in that folder.

Does anyone already has code for this - where we are checking for multiple files existence in the destination folder

Regards

Upvotes: 1

Views: 10139

Answers (1)

Diego
Diego

Reputation: 36136

  1. Add a Foreach loop container to your Control Flow
  2. Double click it and select Collection. On Enumerator, select Foreach File Enumerator
  3. Select your folder and the type of file
  4. Select the return type when a file is found. The options are the whole filename including extension and path, the name and extension or simply the name of the file found
  5. Select the checkbox if you want the subfolders
  6. Click on the variables option on the left and then new variable or select an existing variable.

At this point you have each file name on the folder. To prove it, add a script component, double click it, and your variable on the read Only Variable and click on Edit Script. Make your Main like this:

public void Main()
{
    System.Windows.Forms.MessageBox.Show(Dts.Variables["FileName"].Value.ToString());
    Dts.TaskResult = (int)ScriptResults.Success;
}

now, the comparison you can do several ways. I dont know where do you have the "required files" list, but assuming it is on a database, you can add a data flow task and inside of it send the filename to the DB to do the comparisson.

Upvotes: 2

Related Questions