bobbidee
asked on
Create SSIS File Name Dynamically
I have a package that creates source data and exports to flat file and need to name the file with a Name, Date and Time.
I've read that a variable can be created and used with a Script Task but no instruction on where the script task is placed or how to code this.
Any help is appreciated.
I've read that a variable can be created and used with a Script Task but no instruction on where the script task is placed or how to code this.
Any help is appreciated.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Hi, thanks for the quick response from all. I used the script and made the changes below:
Public Sub Main()
'Dim CurYear As String = System.DateTime.Now.ToStri ng("yyyy")
'Dim CurMonth As String = System.DateTime.Now.ToStri ng("MM")
'Dim CurDay As String = System.DateTime.Now.ToStri ng("dd")
'Dim CurHour As String = System.DateTime.Now.ToStri ng("hh")
'Dim CurMin As String = System.DateTime.Now.ToStri ng("mm")
'Dim CurSec As String = System.DateTime.Now.ToStri ng("ss")
'Dim CurMonthDateYear As String = CurMonth + CurDay + CurYear + CurHour + CurMin + CurSec
'Dim DestFile As String = "C:\Users\bobbid\CBB_Data_ Exchange\"
'Dim ProcessedLocation As String = "C:\Users\bobbid\CBB_Data_ Exchange\P rocessed"
'''Move file
'For Each fi As FileInfo In New IO.DirectoryInfo(DestFile) .GetFiles( "CBB_Pract ice_File.t xt")
fi.MoveTo(ProcessedLocatio n & "\" & fi.Name & "_" & CurMonthDateYear)
Next
' ''Delete destionation file if it exists
If System.IO.File.Exists(Dest File) Then System.IO.File.Delete(Dest File)
End If
Dts.TaskResult = ScriptResults.Success
End Sub
The file appears like this: CBB_Practice_File.txt_0725 2013075552 ... I need the date before the .txt And need to separate the hh mm ss with colon (:) between.
Also, I tried to use the expression but what do I put in the properties section?
Many Thanks again,
BobbiDee
Public Sub Main()
'Dim CurYear As String = System.DateTime.Now.ToStri
'Dim CurMonth As String = System.DateTime.Now.ToStri
'Dim CurDay As String = System.DateTime.Now.ToStri
'Dim CurHour As String = System.DateTime.Now.ToStri
'Dim CurMin As String = System.DateTime.Now.ToStri
'Dim CurSec As String = System.DateTime.Now.ToStri
'Dim CurMonthDateYear As String = CurMonth + CurDay + CurYear + CurHour + CurMin + CurSec
'Dim DestFile As String = "C:\Users\bobbid\CBB_Data_
'Dim ProcessedLocation As String = "C:\Users\bobbid\CBB_Data_
'''Move file
'For Each fi As FileInfo In New IO.DirectoryInfo(DestFile)
fi.MoveTo(ProcessedLocatio
Next
' ''Delete destionation file if it exists
If System.IO.File.Exists(Dest
End If
Dts.TaskResult = ScriptResults.Success
End Sub
The file appears like this: CBB_Practice_File.txt_0725
Also, I tried to use the expression but what do I put in the properties section?
Many Thanks again,
BobbiDee
ASKER
Can someone please answer my questions:
how can I get MMddYYYY hh:mm:ss in the script above to work. i have tried
'Dim CurMonthDateYear As String = CurMonth + CurDay + CurYear + ":" + CurHour + CurMin + CurSec
or
how do i use the expression - what do i choose as the property in the script.
Thanks,
Bobbidee
how can I get MMddYYYY hh:mm:ss in the script above to work. i have tried
'Dim CurMonthDateYear As String = CurMonth + CurDay + CurYear + ":" + CurHour + CurMin + CurSec
or
how do i use the expression - what do i choose as the property in the script.
Thanks,
Bobbidee
ASKER
OK. I figured it out on how to use the expression. I was originally using the expression on the script which did not give an option for connection string - used the expression on the file connection.
The script worked fine except that I could not separate the hours miniutes seconds with a colon e.g. hh:mm:ss.
The script worked fine except that I could not separate the hours miniutes seconds with a colon e.g. hh:mm:ss.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you for getting back - I will try this and hope that they won't mind not having the colon in the hour / mins.
I will get back to you and let you know if it works!
Bobbi
I will get back to you and let you know if it works!
Bobbi
ASKER
Hi, this did not work. The file was processed without the date and txt. Not recognized as a txt file.
Bobbi
Bobbi
Hopefully, this will give you a good idea of how to move forward with your task .. copy and paste this code into your Script Task (make sure to select VB code within the Script Task configuration) and then modify as needed.
Open in new window