vbscript Copying a File/Folder


Example

Methods Used:

.CopyFile(Source, Dest [,Overwrite (True/False)]
.CopyFolder(Source, Dest [,Overwrite (True/False)]

The following code illustrates the use of CopyFile method to copy a file to a new location. The same thing can be achieved for the folders by using the CopyFolder method.

Code:

Dim objFso, strSourcePath, strDestPath
strSourcePath = "C:\Users\GS\Desktop\Source.txt"
strDestPath = "C:\Users\GS\Desktop\Dest.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(strSourcePath) then
    objFso.CopyFile strSourcePath, strDestPath, True              'True indicates the overwritting of the file at the destination path i.e, if the file already exists, it will be overwritten
End If
Set objFso = Nothing