VBS Tutorial: Method-copyfile Method _vbs

Source: Internet
Author: User

CopyFile method

Copy one or more files from one location to another.

object.CopyFile source, destination[, overwrite]

Parameters

Object

Required option. Should be the name of the FileSystemObject object.

Source

Required option. A string representing the specified file. When you copy one or more files, you can have wildcard characters in the file name.

Destination

Required option. A string representing the destination location from which to copy the file. Wildcard characters are not allowed.

Overwrite

Options available. A Boolean value indicates whether the existing file is overwritten. If True, overwrites the file or, if False, does not overwrite the existing file. The default value is True. Note that theCopyFile operation cannot be completed, regardless of the value of the overwrite setting, as long as the destination is set to read-only.

Description

Wildcard characters can only be used in the last part of the path of the source parameter. 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"

If source contains wildcards or destination ends with a path delimiter (\), assume that destination is an existing folder and copy the matching file to that folder. Otherwise, assume that destination is the file you want to create. In either case, the following three situations occur when you copy a single file.

    • If destination does not exist, copy source. This is usually what happens.
    • If destination is a file that already exists, an error occurs when overwrite is False . Otherwise, the copy source overwrites the existing file.
    • If the destination is a directory, an error occurs.

If source uses wildcards, but there are no matching files, an error occurs. The CopyFile method stops when it encounters the first error that occurs. This method does not undo any changes made before the error occurred.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.