dynamically rename file name in ssis
I have source files in any format means text files,xml,word,excel...it really does not matter but i want to change all their file name and rename in below format in ssis conastant|current date|current time|constant|constant. In this format fileName should be ex. xyz2010-11-151:20:34256765.987 and every time i run the package it will change time and date dynamically. I have little bit idea of using for each loop. Need more help on that. Thanks in advance.
November 18th, 2010 3:15pm

Set up a Variable called DestinationFileName and use an Expression to evaluate it. build the expression using all the pieces you need. Then use that varialbe in the File System Task as the DestinationVariableTodd C - MSCTS SQL Server 2005 - Please mark posts as answered where appropriate.
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 4:02pm

Thanks But when i am evaluating the expression it does not take all constant integer value for package level variable .So what kind of data type have to assign to variaable so it will take string,time,date and all constant integers values. Thanks in Advance.
November 19th, 2010 9:32am

In the Expression builder, you would need to include a mix of literal stings, variables, and functions. And use Type Casting to get everything converted to String. For example, I typically use a date stamp in the file name for log files, with the date being in the format of YYYYMMDD. So I have this snippet in my expression: (DT_STR, 8, 1252)(YEAR(GETDATE()) * 10000 + MONTH(GETDATE()) * 100 + DAY(GETDATE())) The YEAR/MONTH/DAY format would return an INTEGER of 20101118, and by casting it as STR, I can then concatenate other things. System::MachineName + " " + System::PackageName + <the above expression> + ".txt" is good for my log files. You get the idea. Todd C - MSCTS SQL Server 2005 - Please mark posts as answered where appropriate.
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 3:23pm

In the Expression builder, you would need to include a mix of literal stings, variables, and functions. And use Type Casting to get everything converted to String. For example, I typically use a date stamp in the file name for log files, with the date being in the format of YYYYMMDD. So I have this snippet in my expression: (DT_STR, 8, 1252)(YEAR(GETDATE()) * 10000 + MONTH(GETDATE()) * 100 + DAY(GETDATE())) The YEAR/MONTH/DAY format would return an INTEGER of 20101118, and by casting it as STR, I can then concatenate other things. System::MachineName + " " + System::PackageName + <the above expression> + ".txt" is good for my log files. You get the idea. Todd C - MSCTS SQL Server 2005 - Please mark posts as answered where appropriate.
November 19th, 2010 3:23pm

first see http://plexussql.blogspot.com/2009/11/coping-files-in-ssis.html and use the code with the conbination of.... go to http://plexussql.blogspot.com/2010/04/looping-through-excel-files-and-sheets.html on see step 13 it has a script that will make the STRING of the format that you want (you need to change it a little) and then moves (renames the file) to a new location with a new name Sincerely SH -- MVP, MCITP 2008, MCTS 2008 & 2005 -- Please kindly mark the post(s) that answered your question and/or vote for the post(s).
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 3:35pm

first see http://plexussql.blogspot.com/2009/11/coping-files-in-ssis.html and use the code with the conbination of.... go to http://plexussql.blogspot.com/2010/04/looping-through-excel-files-and-sheets.html on see step 13 it has a script that will make the STRING of the format that you want (you need to change it a little) and then moves (renames the file) to a new location with a new name Sincerely SH -- MVP, MCITP 2008, MCTS 2008 & 2005 -- Please kindly mark the post(s) that answered your question and/or vote for the post(s).
November 19th, 2010 3:35pm

Thanks Todd and Nik. i got the solution.Iused the destinationfileaname variable at package level scope using string datatype and it works The Expression: "xyz"+(DT_WSTR,4)YEAR(GETDATE() )+ RIGHT( "0"+(DT_WSTR,2)MONTH(GETDATE()),2) + RIGHT( (DT_WSTR,2)DAY(GETDATE()), 2)+ RIGHT( "0"+(DT_WSTR,2)DATEPART("HH",GETDATE()), 2)+ RIGHT( "0"+(DT_WSTR,2)DATEPART("MI",GETDATE()), 2)+ RIGHT( "0"+(DT_WSTR,2)DATEPART("SS",GETDATE()), 2)+"576"+"600"+".110" I put the variable in file system task in destinationvariable property and then i store variable value using derived column.Everything is good,but it change only one file at a time because in sourcevariable property of file system task i assigened a variable which has a static value of a filepath but instead of one file i want to change name of bunch of files usinf for each loop.But i dont know how,can someone help on it. Thanks and all your help is higly appriciated!!!
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 5:08pm

Thanks Todd and Nik. i got the solution.Iused the destinationfileaname variable at package level scope using string datatype and it works The Expression: "xyz"+(DT_WSTR,4)YEAR(GETDATE() )+ RIGHT( "0"+(DT_WSTR,2)MONTH(GETDATE()),2) + RIGHT( (DT_WSTR,2)DAY(GETDATE()), 2)+ RIGHT( "0"+(DT_WSTR,2)DATEPART("HH",GETDATE()), 2)+ RIGHT( "0"+(DT_WSTR,2)DATEPART("MI",GETDATE()), 2)+ RIGHT( "0"+(DT_WSTR,2)DATEPART("SS",GETDATE()), 2)+"576"+"600"+".110" I put the variable in file system task in destinationvariable property and then i store variable value using derived column.Everything is good,but it change only one file at a time because in sourcevariable property of file system task i assigened a variable which has a static value of a filepath but instead of one file i want to change name of bunch of files usinf for each loop.But i dont know how,can someone help on it. Thanks and all your help is higly appriciated!!!
November 19th, 2010 5:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics