O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

FileSystemObject.CopyFile Method

Syntax

                  oFileSysObj
                  .CopyFile Source, Destination [, OverwriteFiles]
oFileSysObj

Use: Required

Data Type: FileSystemObject object

A FileSystemObject object.

Source

Use: Required

Data Type: String

The path and name of the file to be copied. The path can be relative or absolute, and the filename (but not the path) can contain wildcard characters.

Destination

Use: Required

Data Type: String

The path and optionally the filename of the copy to make. Destination cannot include wildcard characters.

OverwriteFiles

Use: Optional

Data Type: Boolean

Flag indicating whether an existing file is to be overwritten (True) or not (False). It’s default value is True; files of the same names in the target folder will be overwritten.

Description

Copies a file or files from one folder to another.

Rules at a Glance

  • The default value for OverwriteFiles is True.

  • The source path can be relative or absolute.

  • The source filename can contain wildcard characters; the source path can’t.

  • Wildcard characters can’t be included in Destination.

Programming Tips and Gotchas

  • If the destination path or file is read-only, the CopyFile method fails, regardless of the value of OverwriteFiles and generates runtime error 70, “Permission Denied.”

  • If OverwriteFiles is set to False and the file exists in Destination, a trappable error—runtime error 58, “File Already Exists”—is generated.

  • If an error occurs while copying more than one file, the CopyFile method exits immediately, thereby leaving the rest of the files ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required