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

File.Copy Method

Syntax

                  oFileObj.Copy Destination [, OverwriteFiles]
oFileObj

Use: Required

Data Type: File object

A File object.

Destination

Use: Required

Data Type: String

The path and, optionally, the filename of the copied file.

OverwriteFiles

Use: Optional

Data Type: Boolean

True if the copy operation can overwrite an existing file, False otherwise.

Description

Copies the file represented by oFileObj to another location.

Rules at a Glance

Wildcard characters can’t be used in Destination.

Programming Tips and Gotchas

  • If the Destination path is set to read-only, the Copy method fails regardless of the OverwriteFiles setting and generates a “Permission denied” error.

  • If OverwriteFiles is False and the file already exists in Destination, runtime error 58, “File Already Exists,” is generated.

  • If the user has adequate rights, Destination can be a network path or share name. For example:

    MyFile.Copy "\\NTSERV1\d$\RootTwo\"
    MyFile.Copy "\\NTSERV1\RootTest"

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