Copyfile Method
Copy one or more files from one location to another.
Object.CopyfileSource, destination [, overwrite]
Parameters
Object
Required. The name of the FileSystemObject object.
Source
Required. Indicates the string of the specified file. To copy one or more files, the file name can contain wildcards.
Destination
Required. String indicating the target location, fromSourceCopy the file to this location. Wildcards are not allowed.
Overwrite
Optional. Boolean indicates whether to overwrite existing files. If yesTrueTo overwrite the file.FalseDoes not overwrite the existing file. The default value isTrue. Note thatOverwriteSet the value.DestinationIs read-only,CopyfileThe operation cannot be completed.
Description
OnlySourceWildcard characters are used in the last component of the parameter path. For example, you can use:
FileSystemObject. copyfile "C: \ mydocuments \ letters \ *. Doc", "C: \ tempfolder \"
However, you cannot use:
FileSystemObject. copyfile "C: \ mydocuments \ * \ R1 ??? 97. xls "," C: \ tempfolder"
IfSourceContains wildcards orDestinationEnd with path separator (\), it is assumedDestinationIs an existing folder, copy the matching file to this folder. Otherwise, assumeDestinationFor the file to be created. In either case, the following three conditions may occur when copying a single file.
- IfDestinationIf not, copySource. This is usually the case.
- IfDestinationIs an existing file, whenOverwriteIsFalseAn error occurs. Otherwise, copySourceOverwrite existing files.
- IfDestinationIs a directory, an error occurs.
IfSourceIf a wildcard is used but no matching file exists, an error occurs.CopyfileMethod stops when the first error occurs. This method does not cancel any changes made before the error occurs.