複製 FileFolder

使用方法:

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

以下程式碼說明了使用 CopyFile 方法將檔案複製到新位置。使用 CopyFolder 方法可以為資料夾實現相同的功能。

碼:

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