Name
FileSystemObject.CopyFile Method
Syntax
oFileSysObj.CopyFileSource,Destination[,OverwriteFiles]
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
SourceUse: 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.
DestinationUse: Required
Data Type: String
The path and optionally the filename of the copy to make.
Destinationcannot include wildcard characters.OverwriteFilesUse: 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
OverwriteFilesisTrue.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
OverwriteFilesand generates runtime error 70, “Permission Denied.”If
OverwriteFilesis set toFalseand 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access