Name
FileSystemObject.CopyFile Method
Syntax
oFileSysObj
.CopyFileSource
,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 isTrue
; 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
isTrue
.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 toFalse
and the file exists inDestination
, 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 ...
Get VBScript in a Nutshell, 2nd Edition 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.