Renaming a file in ActiveX SCript within a DTS

Posted on 2005-04-19
Last Modified: 2013-11-30
Renaming a file in ActiveX SCript within a DTS

I want to rename a file from within a Visual Basic ACtiveX script, I want to use the current date and time to create a dymanic file name

Here's an example of what I want the name to look like (04/19/2005 09:23:10)

Question by:musclejack
    LVL 5

    Expert Comment

    Getting the time string is simple enough
    SELECT CONVERT(VARCHAR,getdate(),112) +
               REPLACE(CONVERT(VARCHAR,getdate(),114), ':', '')

    or any manipulations of this code.
    However, changing the name of a file within a DTS is more complicated.
    I don't think that it is possible since the file name has to be fixed in order to be a valid ODBC datasource (which DTS uses).
    However, I have not done enough work under this particular issue, in order to be 100% sure.

    Hope this help,

    LVL 75

    Accepted Solution

    Try it this way:

    Dim FileName
    FileName = "DTS_" & FormatDateTime( Now(), vbGeneralDate)
    FileName = Replace(FileName, "/", vbNullString)
    FileName = Replace(FileName, " ", vbNullString)
    FileName = Replace(FileName, ":", vbNullString)
    LVL 13

    Expert Comment

    'International setting independent code
    dim NewFileName
    dim NewPath
    dim OldFileName
    dim CurrentDT

    OldFileName = "I:\PROJECT_X\IMPORT\SYSTEM_Y\datafile"

    CurrentDT = Now()
    NewFileName = "DTS_"&right("0"&month(CurrentDT),2)&right("0"&day(CurrentDT),2)&year(CurrentDT)
    NewFileName = NewFileName&right("0"&hour(CurrentDT),2)&right("0"&minute(CurrentDT),2)
    NewFileName = NewFileName&right("0"&second(CurrentDT),2)
    NewFileName = NewPath&NewFileName

    CreateObject("Scripting.FileSystemObject").GetFile(txtFileSource).Move NewFileName

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now