Table of Content

copy or rename files

Handy copy or rename files vbscript.


Private Sub CopyFiles(sFile, sFolder, dFolderFile)

Set fso = CreateObject("Scripting.FileSystemObject")

'Copy the file
If TestFiles(sFile, sFolder) Then
    fso.CopyFile sFolder & sFile, dFolderFile, True
Else
    MsgBox "File: " & sFolder & sFile & " not existing!"
End If

Set fso = Nothing

End Sub

test script

you can copy files from source folder to target folder, or rename specific file to target file in target folder, here is test script.


Private Sub copyfiletest()

CopyFiles "source*", "c:\source\", "c:\target\"
CopyFiles "source.txt", "c:\source\", "c:\target\target.txt"


End Sub