SSIS - Archive Files And Add Timestamp To Each File Name [How To Use File System Task]

Scenario: 

There are different types of files we have in our Source folder. We want to archive them to Archive folder. While archiving them we want to add time-stamp with  each file name.

Solution :

We will be using For-each loop and File System task to perform this task. Let's start with our step by step approach

Step 1: 
Create two variable VarSourceFolder and VarArchiveFolder and provide the values

Step 2: 
Bring For-each Loop container to Control Flow Pane and configure as shown below. I used the VarSourceFolder variable as Directory.  If we need to change Source Folder Path,We do not have to open the package , Instead we can just change the value for this variable by using SSIS Configuration.

The Information we want to extract is File Name and extension , Choose that.

Create variable VarFileName to hold the FileName and extension
The For-each loop is loop through the folder files one by one and on each iteration file name and extension will be saved in VarFileName variable.


Step 3: 
Create a new variable VarArchiveFullPath, Click on that and press F4, that will take you to properties. Go to expressions and paste below expression

@[User::VarArchiveFolder]+"\\"+ Replace(Replace(Replace(Replace( @[User::VarFileName],".","_"+Substring((DT_WSTR,50) GETDATE(),1,19)+"."),"-",""),":","")," ","_")

Set EvaluteAsExpression=True


Step 4:
Create a variable VarSourceFullPath, this will have Source Folder path and file name together. Write expressions on it as shown below


Step 5:
Bring File System task to Control Flow Pane and configure as shown below

Final Output:
Let's run our SSIS Package and see if files are moved and renamed.

As we can see that all the files are moved from Source Folder to Archive Folder successfully and Time-Stamp is also added.

6 comments:

  1. National flags come in excess of twelve unique proportions, from the splendidly square Switzerland to the extended Qatar, the main Flags whose width is more than twice its tallness. Be that as it may, at the Olympics, for reasonableness, they are no different.
    Visit: Flags Of The World

    ReplyDelete
  2. Extremely valuable and relevant information, much appreciated

    data backup solutions for small business

    ReplyDelete
  3. Considerable article, I found this resource utmost beneficial for everyone,thank you for sharing the thoughts,We at Property Hunters shifted this service to a level much higher than the broker concept. If you willing to purchase property in Qatar please visit us,you can see more details like this article Properties For Sale in Qatar

    ReplyDelete
  4. I think this is a very useful way and tool in which one looks for solving more of complex IT problems and ways.One needs to emphasise more on this as well.

    SSIS Postgresql Write

    ReplyDelete
  5. I had to renew my Urgent passport quickly due to a family issue overseas. I fretted about the hurry, but the expedited passport service changed everything. After a simple online application, I scheduled an appointment at the local passport bureau. The staff was kind and worked quickly to renew my passport within a few days. Knowing such services are accessible for unforeseen events makes a difficult moment easier. Thanks to the passport office for their quick help!

    ReplyDelete