ahmedcheema
Programmer
I've created a script task that checks whether a flat file exists before the data flow task is executed and that the file was last updated today, but I'm having some trouble with checking for the file size. After making sure that the file exists I would like to make sure that the file is larger than x bytes.
Here is my VB code from script task:
I use an expression in the precedence constraint to check that the file is from the same date as when the package runs.
DATEDIFF("dd",@[User::FileUpdateDate],@[System::StartTime])==0
Every time I've attempted to write the file size to a variable I get a DTS Script Error: Exception has been thrown by the target of an invocation.
Thanks for your help.
Here is my VB code from script task:
Code:
Public Sub Main()
' GET THE FILE LOCATION & WRITE IT TO THE 'FilePath' VARIABLE.
Dim File_Location As String = CType(Dts.Variables("User::FilePath").Value, String)
' DEFINE A DATESTAMP FOR FILE UPDATE DATE & TIME (LAST WRITTEN)
Dim File_DateStamp As Date
' IF THE FILE EXISTS, RECORD THE UPDATE DATESTAMP
If My.Computer.FileSystem.FileExists(File_Location) Then
File_DateStamp = FileDateTime(File_Location)
Dts.Variables("User::FileUpdateDate").Value = File_DateStamp
Dts.TaskResult = ScriptResults.Success
' UNCOMMENT FOR TESTING THE OUTPUT
' MsgBox("File Date_Stamp: " & File_DateStamp)
' IF THE FILE DOES NOT EXIST, RETURN FAILURE
Else
MsgBox("File not found.")
Dts.TaskResult = ScriptResults.Failure
End If
End Sub
I use an expression in the precedence constraint to check that the file is from the same date as when the package runs.
DATEDIFF("dd",@[User::FileUpdateDate],@[System::StartTime])==0
Every time I've attempted to write the file size to a variable I get a DTS Script Error: Exception has been thrown by the target of an invocation.
Thanks for your help.