rename file task inside for each loop container

  • Hi There,

    I want to use a for each loop container to rename (and move) all the *.csv files in a specified directory. In that directory I have three csv files

    test1.csv

    test2.csv

    test3.csv

    I want to move and rename those files into another directory where they will be renamed as

    test1+(todays date&time).csv

    test2+(todays date&time).csv

    test3+(todays date&time).csv

    Now I have this working as individual file systems tasks for each file, but I want to a little more complex and use 1 file system task in a for each loop container.

    I have a variable called DateTimeNow with an expression that returns the current date and time as string:,

    RIGHT("0" + (DT_STR,4,1252) DatePart("yyyy",getdate()),4) +

    Right("0" + (DT_STR,4,1252) DatePart("m",getdate()),2) +

    Right("0" + (DT_STR,4,1252) DatePart("d",getdate()),2) +

    "_" +

    Right("0" + (DT_STR,4,1252) DatePart("Hh",getdate()),2) +

    Right("0" + (DT_STR,4,1252) DatePart("Mi",getdate()),2)

    but how can I tell the loop container to append this string to each of the 3 file names? Hope I make sense. I'm not quite sure how to correctly specify the destination variable in the file system task and what variables(s) mappings to specify in the for each loop container. So what variable will represent the 3 files and where does that variable need to be configured?

    Many thanks

  • If anybody needs to know how accomplish a simular task the solution is create a string variable. Then in the for each loop container set that variable in the variable mappings section.

    Then in file system task set the same varaible as the source connection.

    The is a good demonstration here:

    http://www.sqlis.com/post/Looping-over-files-with-the-Foreach-Loop.aspx

    thanks

  • Here is a video on how to do the same...sometimes with SSIS it helps to see someone develop it realtime:

    Looping Through and Loading Files with SSIS

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply