Script Task Help Needed

  • I am converting an ActiveX VBScript I used in SQL Server 2000 DTS to a VB.Net script for the Script Task in SSIS.  This script checks the date on each file and then moves the file to a different directory if the date does not match todays date.

    I looked at the File System Task but it looks like that one is only designed to move, copy, rename, or delete files and can only handle one file at a time.  Very inconvenient when I have 17 txt files and it can't check the date on the file.  It will be much easier to write a script to do both at the same time.  Unless someone knows a simpler way.

    Anyway I am trying to use the following code to access the file info:

    Dim

    objFSO As Object, objFolder As Object, objFile As Object, colFiles As String, objFSO2 As Object

    objFSO2 = CreateObject(

    "Scripting.FileSystemObject")

    objFSO = CreateObject(

    "Scripting.FileSystemObject")

    objFolder = objFSO.GetFolder(

    "C:\Imports\Data".Value)

    colFiles = objFolder.Files

    And get the following error:

    Error 30574: Option Strict On disallows late binding.

    How can I avoid this error?

    Or am I doing this wrong for VB.NET?

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

  • I have found a way to view the file names. 

    The problem now is that for some reason the creationdate is storing previous values instead of clearing them out.

    For example I created a file as test.txt as 12:14:03 PM today.  Then I renamed it to test1.txt and created a new test.txt at 12:15PM.  When I run the below script it gives me the time as 12:14:03 PM for both test files.  Does anyone know why it would be doing this?

    This is what I have so far:

     

    'This task checks the file creation date for all text files unziped by a

    'previous task. It moves all files that do not have todays date to an

    'alternate folder and uses a count of remaining files to set update type.

    Imports

    System

    Imports

    System.Data

    Imports

    System.Math

    Imports

    System.IO

    Imports

    Microsoft.SqlServer.Dts.Runtime

    Public

    Class ScriptMain

    Public Sub Main()

    Dim sFileName As String

    sFileName =

    "C:/data/data.txt"

    Dim fFile As New FileInfo(sFileName)

    If Not fFile.Exists Then

    MsgBox(

    "File Not Found")

    Else

    MsgBox(

    "File Found. File was created on: " & fFile.CreationTime)

    End If

    FileNames(

    New DirectoryInfo("c:\data"))

    Dts.TaskResult = Dts.Results.Success

    End Sub

    Sub FileNames(ByVal dir As DirectoryInfo)

    Dim objFile As FileInfo

    For Each objFile In dir.GetFiles("*.txt")

    MsgBox(objFile.FullName &

    " " & objFile.CreationTime)

    Next

    objFile =

    Nothing

    End Sub

    End

    Class

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

  • Hi ,

    Try to create a new file with another name that test.txt. Maybe there is a reference still active on the filename in Windows.

  • New file names are fine it will get the date right the first time.  But I will get the same file name every day with different data and I need the process to be able to detect the different date on the file.  I just ran the process again and I still has the same dates from yesterday, which for most of the files is wrong.

    Is there a way to clear that reference from being active on the filename in Windows without rebooting the computer?

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

  • Try using the LastWriteTime property instead of the CreationTime property.  Once the file exists, updates will not affect the CreationTime property, but each time it is written the LastWriteTime will be updated.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply