Getting File Information with the Script Task

A requirement for a current client is to capture some information about Flat Files being loaded for logging purposes. Fortunately this is a easy job for the Script Task, using the following VB.Net code:

Public Sub Main()

‘ String variable to hold file name
Dim strFileName As String

‘ File name (including path) passed in from container
strFileName = Dts.Variables(“User::FileName”).Value.ToString

‘ Create a System.IO.FileInfo object to retrieve the data
Dim FileObject As System.IO.FileInfo = New System.IO.FileInfo(strFileName)

‘ Return the information via a message box
MsgBox(“File name ” + FileObject.FullName + ” created on ” + FileObject.CreationTime.ToString)

End Sub

The sample package for this post can be found here. To see what other properties can be obtained, just use Intellisense on the FileObject object in the code.

One thought on “Getting File Information with the Script Task

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>