March 7, 2008 at 7:36 am
I am try to set two variables with this script and pass them back to variable in a package. The variables are entered as ReadWrite and have package scope. If I send an invalid directory variable as ArchiveFolder I get a run time error in the MkDir statement. If I send a valid construct the folder is created. Can someone please tell me just what I'm doing wrong.:sick:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim Archive As String
Dim FTP As String
Dim DateString As String
DateString = Right("0000" & DatePart(DateInterval.Year, Now), 4)
DateString = DateString & Right("00" & DatePart(DateInterval.Month, Now), 2)
DateString = DateString & Right("00" & DatePart(DateInterval.Day, Now), 2)
Archive = "c:\Test Files\" & DateString
FTP = "/out/export/hist/" & DateString & "*.*"
Archive = Archive & DateString
FTP = FTP & DateString & "/*.*"
MkDir(Archive)
Dts.Variables("ArchiveFolder").Value = Archive
Dts.Variables("FTPFolder").Value = FTP
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
Tim
March 7, 2008 at 9:44 am
Instead of MkDir consider using the methods available in My.Computer.FileSystem.
Reference:
How to: Determine if a Directory Exists in Visual Basic
How to: Create a Directory in Visual Basic
If you stay with the MkDir function use a try/catch block.
Try
MkDir(myFolder)
Catch ioex as IO.IOException
MsgBox("Folder exists.")
End Try
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply