Name | Scope | Data Type | Value |
---|---|---|---|
FileName | [Package Scope] | string | |
SourceFolder | [Package Scope] | string | [Source Folder Path] (example :- c:\Source_Folder) |
SourcePath | [Package Scope] | string | |
TargetFolder | [Package Scope] | string | [Target Folder Path] (example :- c:\Archive_Folder) |
ArchivePath | [Package Scope] | string |
Variable Name | EvaluateAs Expression |
Expression |
SourcePath | true | @[User::SourceFolder]+"\\"+ @[User::FileName] |
ArchivePath | true | @[User::TargetFolder] +"\\"+REVERSE(SUBSTRING(REVERSE( @[User::FileName] ),FINDSTRING(REVERSE(@[User::FileName] ),".",1)+1,LEN(@[User::FileName])- FINDSTRING(REVERSE(@[User::FileName] ),".",1))) +"_"+ Right("0" +(DT_STR,4,1252) datepart("yyyy", getdate()),2) + Right("0" +(DT_STR,2,1252) datepart("mm", getdate()) ,2) + Right("0" +(DT_STR,2,1252) datepart("dd", getdate()),2)+Right("0" + (DT_STR,2,1252) DatePart("hh",getdate()),2) + Right("0" + (DT_STR,2,1252) DatePart("mi",getdate()),2) + Right("0" + (DT_STR,4,1252) DatePart("ss",getdate()),2)+REVERSE(SUBSTRING(REVERSE( @[User::FileName] ),1,FINDSTRING(REVERSE(@[User::FileName] ),".",1))) |
3. Add For each Loop Container and set properties :Now, lets loop thru the folder and process each file from the folder by “For Each loop”. Here, we can setup the folder by Expressions->Directory use Expression @[User::SourceFolder]. We should also specify which type of files we are going to process, like “txt”, “csv” etc..by specifying the same in “Files”. We are fetching the file name with extension so that option needs to be selected as displayed in the following screenshot.
We need to assign each file name to the variable, by Variable Mappings->set variable [User::FileName] and Index as 0
4. Add File System Task:Add “File System Task” inside “For each Loop Container”
5. Set properties for File System Task:This is the place where we need to setup the operation, which will do our job.
A. Configure SourceVariable
B. Configure DestinationVariable
C. Select operation: “Rename File”, which will rename the file and move it to the Archive Folder as we have specified in variable.
6. Run package and check
With SSIS, it is much simple to process multiple files as mentioned above.
Microsoft Certified Professional Expert. I have 14+ years of experience in Design and Develop 100+ .Net applications using Asp.Net, C#, Asp.Net Core, VB.Net, SQL Server, MVC, AngularJS, JavaScript, Azure, HTML5 and CSS3.
Posted by Tejas Shah on November 22, 2017
Posted by Tejas Shah on November 11, 2017
Posted by Tejas Shah on August 12, 2015
Posted by Tejas Shah on June 26, 2015
Posted by Tejas Shah on April 20, 2015