How can i change Flat file path using foreach loop container in SSIS
I’m having flat file which is under c:\sourcefile name of the file is “Flat(Date)”
for e.g Flat01aug2011.csv
and every day it is generated by recent date so i need to picked up new file always and pass it to Flat File destination ,
so how can i traverse through folder and take new file which is having recent date.???
Example in the below given link shows how you can loop through files of a given extension and load them into a database using Data Flow Task.
The example loads .csv files. The package uses a
Foreach loop containerto loop through the files and there is aData Flow taskwithin the loop container. The Data Flow task contains a Flat file source which changes based on the file being looped through. This is done by altering the Flat File Connection Manager path.How do I move files to an archive folder after the files have been processed?
Here is an example that loops through a list of directories within a given directory and picks the most recently created folder using Script Task and Foreach loop container. You need to make use of a similar logic to pick the most recently created file.
How do I pick the most recently created folder using Foreach loop container in SSIS package?
Hope that helps.
Update:
Create two string data type variables namely
DirPathandFilePath. Set the value C:\backup\ to the variableDirPath. Do not set any value to the variableFilePath.Select the variable
FilePathand select F4 to view the properties. Set theEvaluateAsExpressionproperty to True and set the Expression property as@[User::DirPath] + "Source" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE()) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)