I have four files xxxxxxCd999, xxxxCf999, xxxxC999 , xxxxD999 ... I need to move these files to their respective folders based on file name , for example file xxxxxCd999 should be moved to folder Cd999 , file xxxxCf999 should be moved to folder Cf999 ,file xxxC999 should ne moved to folder C999 so on ... How do I achieve this in ssis ?
I have used a for each loop container, assigned some variables for sourcepath, destinationpath , and a file system task to use these variables , but im lost now n have no idea how to proceed , Kindly help me
Try this :-
The
Foreach Loop
will enumerate the source folder and the path will be stored in a variable. In thescript task
write a code to get the folder Name using regular expression .The script task value will be stored in another variable which will be used inFile System Task
The package design will be
Create 3 variable
In the above expression for
DestLoc
variable ,change it as per your locationChange the source folder location as per the need
Script task -Add the 2 variable as below
You need to extract the folder name from the variable
LoopFiles
Example
LoopFiles
variable will haveD:\ForLoop\SampleFolder1.txt
at runtimeSo in order to extract folder name from the above variable use regular expression
Open
Edit Script
and write the following codeIn the above code ,you are extracting the folder name and storing it in the variable
FolderName
.If you havemultiple folders
,then just add thefolder names
to thefilePatterns
collection variable.