Script Task / File Rename

  • I was sure this would ahve been simple but I can't seem to get this to work. I just want to rename a csv file to the date in a dd-mm-yyyy format. I created a script task to do so and I'm not having any luck.

    Hy code is here

    Public Sub Main()

    Try

    Dim td As String = Now.Date.ToString()

    File.Move("E:\filesewfile.csv", "E:\files\" & td & ".csv")

    Catch ex As Exception

    Dts.Events.FireError(1, "File error", "", "", 0)

    End Try

    Dts.TaskResult = Dts.Results.Success

    End Sub

    My task fails.

    Is there no way for me to step through this code to figure out where it is going wrong? I have tried dts variables too. They work, but I don't know how to get the date in there.

  • Try the FileSystem task. I use it in several SSIS projects.

  • Apprently string concats are + and not &

    I thought this is supposed to be VB.NET?

  • I just looked at one of my SSIS packages that has a Script Task, and I am using the & to concatenate strings.

    😎

    This is the code in my script.

    Public Class ScriptMain

    Public Sub Main()

    Dim FileDate As String

    FileDate = Format(Dts.Variables("StartTime").Value, "yyyyMMdd")

    Dts.Variables("DestinationFileLocation").Value = CStr(Dts.Variables("DestinationFileLocation").Value) & "\" & FileDate

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

  • Are you sure that this is the correct path? AFAIK "E:\" means E on the server not the client.

Viewing 5 posts - 1 through 4 (of 4 total)

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