?
Solved

Renaming a file in ActiveX SCript within a DTS

Posted on 2005-04-19
3
Medium Priority
?
617 Views
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)

DTS_04192005092310
0
Comment
Question by:musclejack
3 Comments
 
LVL 5

Expert Comment

by:obahat
ID: 13817201
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,

Omri.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 13817392
Try it this way:

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

Expert Comment

by:ispaleny
ID: 13818337
'International setting independent code
dim NewFileName
dim NewPath
dim OldFileName
dim CurrentDT

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

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
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

807 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