0

I have a task that should rename a file

I have a variable called RenameFileName

\\servername\csv\BACKUP\" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv

When I run the task I get the error

Illegal characters in path

Am I doing anything wrong? Below are a list of the variables I have tried

\\\\servername\\csv\\BACKUP\\" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv

\servername\csv\BACKUP" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv

"\servername\csv\BACKUP" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv"

"\\servername\csv\BACKUP\" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv"

Please note that the following works:

\\\\servername\\csv\\BACKUP\\ABC.csv

This however does not work

\\\\servername\\csv\\BACKUP\\"+1+".csv

It errors as soon a I put in double quotes. Single quotes are fine and they get put in the filename

Thanks

pee2pee
  • 194
  • 1
  • 3
  • 9

1 Answers1

2
\\\\servername\\csv\\BACKUP\\" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv

You almost had it here but you missed the leading and trailing quotes.

\\servername\csv\BACKUP\" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv

Now you're missing the leading and trailing quotes and you failed to escape your back slashes.

"\servername\csv\BACKUP" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv"

Now you've got the quotes but not escaping the backslashes

"\\servername\csv\BACKUP\" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + ".csv"

This works correctly for me in SSIS expression.

correctly working

FYI \\servername\csv\BACKUP\"+1+".csv

again you are missing the leading and trailing quotes. However this won't work because it sees 1 as an integer and you need to convert it.

"\\\\servername\\csv\\BACKUP\\"+"1"+".csv"

The above works.

Normally when doing these sorts of expressions I do it iteratively. Adding 1 piece to the expression at a time so if it breaks I know where it broke. Remember you can click "evaluate expression" to see the result.

If the expression evaluates correctly but the package doesn't work then it would be another issue with the package.

Bee_Riii
  • 165
  • 7