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.

About BI Monkey

Comments

One Response to “Getting File Information with the Script Task”
  1. Peter says:

    Thanks, just what I was looking for !

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!