SSIS For each Container with file task

  • SSIS For each Container with file task

    I am trying to rename a file that is place in a directory every month with different names. I can get a rename to work but its just appending to what is there. I need to know how the expression would work to replace what's there with what I need.

    example 4254_output.txt I need to have it output.txt

    when I use the my expression in the variables I created I get 4254_output.txtoutput.txt

    Thanks in advance

  • If you are doing it for single file as you have mentioned you can try this:

    System.IO.File.Move(Dts.Variables["strSourceFile"].Value.ToString(), "D:\\Temp\\output.txt");

    Where the first parameter is your variable name.

    If you are looking for expression and I am assuming that your file name is alwasy XXXX_output.txt where XXXX is any character than you can try

    System.Windows.Forms.MessageBox.Show(Dts.Variables["strSourceFile"].Value.ToString().Substring(Dts.Variables["strSourceFile"].Value.ToString().LastIndexOf("_")+1,(Dts.Variables["strSourceFile"].Value.ToString().Length-Dts.Variables["strSourceFile"].Value.ToString().LastIndexOf("_"))-1));

    Vikash Kumar Singh || www.singhvikash.in

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

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