Can you please find error in this code ?

  • Hi,

    I am using script task in my package. Here i want to add date to newly created folder, like "folder-30\03\2010" . Using following code i am getting folder name as "Folder-30".

    Can you anybody suggest me how to get output as like "Folder-30\03\2010"

    Public Sub Main()

    Dim FileDate, InFolderName As String

    Dim strDay, strMonth, strYear As String

    InFolderName = Dts.Variables("User::InFolderName").Value.ToString()

    InFolderName.Trim()

    strDay = DateTime.Now.Day.ToString()

    strMonth = DateTime.Now.Month.ToString()

    strYear = DateTime.Now.Year.ToString()

    FileDate = "-" + strDay + "\" + strMonth + "\" + strYear

    InFolderName = InFolderName + FileDate

    MessageBox.Show(InFolderName.ToString())

    Dts.Variables("User::InFolderName").Value = InFolderName

    Dts.TaskResult = Dts.Results.Success

    End Sub

  • Folder names cannot contain slashes. Try replacing slash with - and you should have more luck.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Replace "+" with "&" that should do it

    FileDate = "-" & strDay & "\" & strMonth & "\" & strYear

  • Wrong. File names and folder names cannot contain slashes.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Phil Parkin (3/30/2010)


    Wrong. File names and folder names cannot contain slashes.

    🙂 I agree with you on that Phill, I was just trying to help him with the code their.. because using "+" was just getting him part of the name and If I understand correctly he wasn't able to get the Complete Folder Name as he was expecting in the "message box"

    FileDate = "-" + strDay + "\" + strMonth + "\" + strYear

    InFolderName = InFolderName + FileDate

    MessageBox.Show(InFolderName.ToString())

    Dts.Variables("User::InFolderName").Value = InFolderName

  • divyanth (3/30/2010)


    Phil Parkin (3/30/2010)


    Wrong. File names and folder names cannot contain slashes.

    🙂 I agree with you on that Phill, I was just trying to help him with the code their.. because using "+" was just getting him part of the name and If I understand correctly he wasn't able to get the Complete Folder Name as he was expecting in the "message box"

    FileDate = "-" + strDay + "\" + strMonth + "\" + strYear

    InFolderName = InFolderName + FileDate

    MessageBox.Show(InFolderName.ToString())

    Dts.Variables("User::InFolderName").Value = InFolderName

    Sorry. Blood pressure too high 🙂 Think I'll take a break...

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Thank you all.

    Following code working fine for me

    FileDate = "-" + strDay + strMonth + strYear

Viewing 7 posts - 1 through 6 (of 6 total)

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