CopyFile

Product Feedback
Feedback

Syntax

CopyFile (szSrcFile, szTargetFile);

Description

The CopyFile function creates a copy of the file specified by szSrcFile. The new file is given the name specified by szTargetFile.

Parameters

szSrcFile

Specifies the name of the file to copy. If the filename is qualified, that is, if it includes a path, CopyFile will copy the file from the specified location. If szSrcFile contains an unqualified filename, that is, without path information, CopyFile will copy from the directory identified by the system variable SRCDIR. To copy groups of files, use wild card characters in this parameter.

szTargetFile

Specifies the name to give to the copy of the file identified by szSrcFile. If the filename is qualified, that is, if it includes a path, CopyFile will copy the file to the location specified by the path. If szSrcFile contains an unqualified filename, that is, without path information, the copy will be created in the directory specified by the system variable TARGETDIR. If the target directory does not exist, it will be created.

Note
When a wildcard character is included in the filename specified by szSrcFile, the filename part of szTargetFile is not ignored as in previous versions of InstallShield Professional; instead, all of szTargetFile is treated as the target path to which each source file is copied to with its existing name. For example, CopyFile( "C:\\*.*", "D:\\File.txt" ) copies files to a folder named File.txt on the D drive. If szTargetFile specifies an unqualified filename, the files are copied to the directory specified by TARGETDIR. For that reason, CopyFile cannot be used to copy and rename a group of files. The source and target directories must be different when szSrcFile contains one or more wildcard characters.

Return values

0

Indicates function successfully copied the file(s) from source to target directory.

< 0

Indicates that the function was unable to copy the requested file.

You can obtain the error message text associated with a large negative return value—for example, -2147024891 (0x80070005)—by calling FormatMessage.

Comments


Example