Name
FileSystemObject.CopyFile Method
Syntax
oFileSysObj
.CopyFileSource
,Destination
[,OverwriteFiles
]
-
oFileSysObj
Use: Required
Data Subtype: FileSystemObject object
Any object variable returning a FileSystemObject object.
-
Source
Use: Required
Data Subtype: 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 Subtype: String
The path and optionally the filename of the copy to make.
Destination
cannot include wildcard characters.-
OverwriteFiles
Use: Optional
Data Subtype: 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 & 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 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 function exits ...
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.