This scenario explains how to loop though the files one by one.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2J8Z6Y_YxdpcQjfgjQ5OLH-VWb_6ZwCMOcMJcDwD0vmvhZC2OLRy08IL7gtnwtPMzDX7_NP-PKrq6169l8uB8b_TELdL4zVcOgzoHsYHUgBa9WH20-ghetUbF0lVoGuFljJSMmXk31J5t/s400/New+Bitmap+Image.bmp)
First step is to define few variables in the system
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKssPmzQ57gGmFBIriCaD9U1pfoO1ZauwTtGRuS96jh18Re7hckpX5GnfBLJwIMewYuOomNws38kRCUj_HYwMjsu6fGPl6N9R_IwuRNSx0wLBB-cdENg0ilqLIqnXu8Cgb7j7hBEN7QY2B/s400/New+Bitmap+Image+(2.5).bmp)
1. uVar_FolderNameOfFilesToBeProcessed : Points to the folder that is required to be processed.
2. uVar_SourceConStr_DataSource : File name and folder gets saved in on each loop
3. uVar_SourceFileExtention : Defines the file extension type
Next is the settings of the Loop
First ---
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSbHpH7Ggi1vyY0YG7nlSMbHvxZnxwIDtH5kcCNHZzuwn1z72PaPt2lTQtgafdtf552bk-VQ74fFSmc-5nxIC8qC0dcIHdYLrxXQokzGvCGbD4gsqT5EcXpYKqA8Qd1aoO98d_5b_F0Rsu/s400/New+Bitmap+Image+(3).bmp)
Second --
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOLXXzyFPqZcA6J7M7xnR8J6otFog_hzE47nYd3o2oHCGuajdxyHa5zeMkjqNN28vE_n7zPjoyMcCkA6bvAYzEsLWd0BWPWDovYR5IeUFMll3UR9ciubIQPFew2lsvuMgzCvcTOilc8jUh/s400/New+Bitmap+Image+(4).bmp)
Next step the script setting
In this section I am going to make it easy, so I am going to use a message box to display the File and folder name.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSo35mr2Wm7xd-u_pJnpD4hXmXNf6G4Tw2pd_kc4MViFZeeYnygeLajNirBiRgvwPxDmRBmZs0UlZtkPk0EQOpbyIQqAEEWY_vQqMaLjd8NadEdltRjcExsYFwV13yb9Lj5GQb6NXfMa7E/s400/New+Bitmap+Image+(5).bmp)
Please Note: SSIS is not a front-end software, the message box is just for test purposes.
next click on the "Design Script" and enter the code....
Public Sub Main()
'
' Add your code here
'
MsgBox(Dts.Variables("uVar_SourceConStr_DataSource").Value.ToString)
Dts.TaskResult = Dts.Results.Success
End Sub
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8YXGOAEdCE-r7HBAjFVmddH1ILasVM909cm9AgJJI2UfcCwNDnjc6Y6N20iLUr8azl1xi3p6NVbphQ5d4Iq8OO2TlfAZnSyUd11iDrNWetxWWNJvWGcb1IixxYDNVpDYl5tlVv1oEH_N5/s400/New+Bitmap+Image+(6).bmp)
Testing Scenarios
Assuming that we have 2 types of file (1- Excel files 2- Text file) .....
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhxvFaWK28Ssck0euk54IRpLb6AyFO1LwAgWjRyMlNR1XOJexGllq2ymvJElU80qzQkvrMkgzfMlKdBH8O1d21WvbH1kadW7GWOr64AxITC1CienWZJkYrCuGoVG37nbEhFdPdX5zeCuSN/s400/New+Bitmap+Image+(7).bmp)
---First test finding *.xls files
In the variable "uVar_SourceFileExtention" we have "*.xls", and in the folders and subfolders we have 2 excel files, once running the SSIS package from BIDS you'll get 2 message box one message for each loop as...
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAZf0I2aXLrRAOLKGJulwb65yd1pEHJdz-K31666bWebjV1U61Cavz6-HRZmEJDmm2pIQFSYjhACci1ssrrxZ9GKgFNkYxdOwpUjruFGX3HFKp8vza5AFFT2HTbOgbDl1dOizCmpQK5eBY/s400/New+Bitmap+Image+(8).bmp)
---Second test finding *.txt files
Change the variable "uVar_SourceFileExtension" to "*.txt", and run the package again in BIDS, you will have to get only one message.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmMW7uHCfwA7yq5OCjK16R-KInv0J_wI55JHMmq_smojPi2GhRysScPuSfWzC-AhuDir1jpDzxPeFwSmgJ9VaXTXH53fLFt52hbyMv4s_rl_3SokbYbnLrTaL9fvdMJ3EQpZtX37LAsJEn/s400/New+Bitmap+Image+(9).bmp)
---Third test finding files with a special extension *30.xls or File*.xls
In this case you will get the same message box as the first scenario except you will only get the first message, file “File20070930.xls”