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

6
  • Looks like you're missing double-quotes in the beginning and end of your code above, not sure if that's just a copy / paste mistake though?
    – J.D.
    Commented Feb 11, 2021 at 12:47
  • I have added double quotes, escaped everything etc but it still errors.
    – pee2pee
    Commented Feb 11, 2021 at 12:49
  • Can you please provide in the question the full current variable you're using?
    – J.D.
    Commented Feb 11, 2021 at 12:50
  • @J.D. I have added some more failures
    – pee2pee
    Commented Feb 11, 2021 at 14:05
  • 1
    "\\\\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" Works for me. Note the leading and trailing quotes. Normally when doing these expressions I do it section by section so if it breaks I know where. FYI the expression \\\\servername\\csv\\BACKUP\\"+1+".csv doesn't work because you're not casting the 1 as a string. and the leading and trailing quotes are missing. "\\\\servername\\csv\\BACKUP\\"+"1"+".csv" works
    – Bee_Riii
    Commented Feb 11, 2021 at 15:11

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.