Name

Folder.Copy Method

Syntax

                  oFolderObj.Copy Destination [, OverwriteFiles]
oFolderObj

Use: Required

Data Subtype: Folder object

Any object variable returning a Folder object.

Destination

Use: Required

Data Subtype: String

The path and, optionally, the filename of the copy to be made.

OverwriteFiles

Use: Optional

Data Subtype: Boolean

Indicates whether existing files and folders should be overwritten (True) or not (False).

Description

Copies the current folder and its contents, including other folders, to another location.

Rules at a Glance

  • Wildcard characters can’t be used in Destination.

  • The folder and all subfolders and files contained in the source folder are copied to Destination. That is, the Copy method is recursive.

  • Unlike the FileSystemObject.CopyFolder method, there is no operational difference between ending Destination with a path separator or not.

Programming Tips & Gotchas

  • If the destination path or any of the files contained in the Destination structure are set to read-only, the Copy method will fail regardless of the value of OverwriteFiles and will generate a “Permission denied” error.

  • If OverwriteFiles is set to False, and the source folder or any of the files contained in the Destination structure exists in the Destination structure, then trappable error 58, “File Already Exists,” is generated.

  • If an error occurs while copying more than one file, the Copy method exits immediately, leaving the rest of the files uncopied. There is also no rollback facility to undo the copies ...

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.