How to import file .txt having a changing name ?

  • Hi,

    I would like to import a text file with DTS. But this text file has a name which changes everytime : CLI0001.txt, CLI0002.txt, CLI0003.txt .... The last 4 numbers are in a table.

    I have created a connection to the text file, a connection to SQL Server and a Data Driven Query Task which inserts the lines in the .txt file in SQL Server.

    Is it possible to change dynamically the name of the .txt file ?

    THANKS 

  • Hi,

    You can use the dynamic properties task to define the txt file dynamically?


    Balaji

  • ...or identify the newest file in the folder (by file timestamp)...?

  • I always force imported files to have the same name everytime.

  • You can save the DTS as a VB package, then change it so the new filename is passed into it or it or it calc's the correct filename to import.

  • You can dynamically change the name of a text file.  One option is to use the ActiveX Script Task in your DTS to perform this name change.  Example:

     

    '**********************************************************************

    '  Visual Basic ActiveX Script

    '************************************************************************

    Function Main()

     Dim FSO

     Set FSO = CreateObject("Scripting.FileSystemObject")

     Dim objFile

     Set objFile = FSO.GetFile("C:\TEMP\MyFile.txt")

     objFile.Name = "MyNewFile.txt"

     Set FSO = Nothing

     Set objFile = Nothing

     Main = DTSTaskExecResult_Success

    End Function

  • This is one of the many questions covered at http://www.sqldts.com

    http://www.sqldts.com/default.aspx?200

    --------------------
    Colt 45 - the original point and click interface

  • Thanks a lot for the replies ! There is what I needed.

    For my last project, I have used only linked server and T-SQL to program my imports for each day.

    So this time I'm trying the DTS.

    But I'm asking how to choose between DTS and linked server/T-SQL for a replication ?

     

     

  • The suggested method works well when you can determine the name.  When you can't, use the following method:

    Dim fso, folder, file, filecollection

    Set fso=CreateObject("Scripting.FileSystemObject")

    Set folder=fso.GetFolder("<<Path>>")

    Set filecollection=folder.Files

    For each file in filecollection

     DTSGlobalVariables("ImportFileName").Value=file.Name

     Exit For

     

    Next

    DTSGlobalVariables("ImportFilePathName").Value="<<Path>>\" & DTSGlobalVariables("ImportFileName").Value

Viewing 9 posts - 1 through 8 (of 8 total)

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