Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

copy and rename file with ActiveX and dts

Hi,

I would like to copy a file to a new location and then rename (attach current date and time) the file at the new location. My code is not working and can't seem to find a solution. Your help is appreciated

Thank you

Roman

Here is my code:

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()

DIM sdate
Dim oFSO
Dim sSourcePath
Dim oFolder
Dim oFileCollection
Dim oFile
DIM sTargetFolder
DIM OldName
DIM NewName

'Customize values here to fit your needs

Set oFSO = CreateObject("Scripting.FileSystemObject")
sSourcePath = "some_location"
sTargetFolder = "some_location_2"
set oFolder = oFSO.GetFolder(sSourcePath)
set oFileCollection = oFolder.Files

'Walk through each file in the source folder.

For each oFile in oFileCollection
If FormatDateTime(oFile.DateLastModified, 2) = FormatDateTime(date(), 2) Then
OldName = oFile.Name
NewName = OldName&date()
Name OldName as NewName -- IT GIVES ERROR HERE
oFile.Copy sTargetFolder &"\",true


End If
Next

'Clean up
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing

Main = DTSTaskExecResult_Success
End Function
[1544 byte] By [rkiss] at [2007-11-11 7:58:35]
# 1 Re: copy and rename file with ActiveX and dts
Try this:

OldName = oFile.Name
NewName = OldName & Date()
oFSO.CopyFile OldName, sTargetFolder & "\" & NewName, True
Phil Weber at 2007-11-11 23:47:30 >
# 2 Re: copy and rename file with ActiveX and dts
Thank you for your reply.

Here is how I accomplished it:

current_date = replace(date(),"/","_")
OldName = oFile.Name
NewName = current_date & "_" & OldName
oFile.Copy sTargetFolder & "\" & NewName, True
'MsgBox sTargetFolder & "\" & NewName
rkiss at 2007-11-11 23:48:30 >