Creating a script to delete txt file after import.

  • Hi all!

    I need some help with DTS package importing a text file. I am importing a text file into a table using the DTS package that runs a job to import this txt file every day at a certain time. I want to be able to delete this txt file after the import is complete. How do I do this? Any help is greatly appreciated.

    Thanks in Advance!

    SD

  • Hi There,

    Use the file scripting object in an ActiveX Task to delete your file after your import step is successful.

    Function Main()

        dim oFSO

    '  instantiate the Scripting Object

        set oFSO = CreateObject("Scripting.FileSystemObject")

    '   Delete the file

        oFSO.DeleteFile("C:\yourfilename.txt")

     Main = DTSTaskExecResult_Success

    End Function

     

    HTH

  • Thanks for your help! I really appreciate it.

    SD

  • When I tried to save the script, it is giving an error.  It says that the job was not saved because all objects that were created were not destroyed.  The error code is 14277.  I added a line that said oFSO.close, but that did not help. 

    Thanks again,

    Shree

  • Hey,

    Never mind! I just found out I needed to set the object to Nothing

    set oFSO = Nothing

    That worked!

    Thanks!

    SD

  • oops! Sorry, forgot that bit !! Always good practice to destroy the object when done.

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

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