Wednesday, January 20, 2010

Move a file with ActiveX in DTS

Once you process a file, you will usually archive it. Often, you may run into cases where the file already exists in the archive directory. Unfortunately, the Move command does not have an overwrite option. You will need to use the Copy command with the Overwrite option.

Function Main()
Dim oFSO
Dim vSourceFile
Dim vDestinationFile

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const OverwriteExisting = True
Const DeleteReadOnly = True

vSourceFile = "\\MySourceDirectory\*.csv"
vDestinationFile = "\\MyDestinationDirectory\"

' Move the files Use OverwriteExisting in case the file is there
objFSO.CopyFile vSourceFile, vDestinationFile, OverwriteExisting

' Delete the files in the source directory
objFSO.DeleteFile(vSourceFile ) , DeleteReadOnly

Set oFSO = Nothing

Main = DTSTaskExecResult_Success


End Function


Now, all of the files in the source directory are now in the archive.

No comments: