copy and rename file with ActiveX and dts
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

