aqFileSystem.CopyFile Method

Applies to TestComplete 14.30, last modified on November 21, 2019

Description

Use the aqFileSystem.CopyFile method to copy one or several files to a new location. The method can resolve possible file name collisions that may occur while copying files.

Declaration

aqFileSystem.CopyFile(PathToExistingFilePathToNewFileRenameOnCollision)

PathToExistingFile [in]    Required    String    
PathToNewFile [in]    Required    String    
RenameOnCollision [in]    Optional    Boolean Default value: True   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

PathToExistingFile

The path to the file to be copied. Both fully-qualified and relative paths are acceptable. To copy several files, use wildcards (* and ?) to specify the mask. Note, that wildcards are only allowed in the file names, not in paths.

PathToNewFile

If PathToExistingFile specifies a single file (not a mask), this parameter can be either the name of the new file to create, or the name of the folder where the original file will be copied.

If PathToExistingFile includes wildcards, this parameter must specify the folder where the matching files will be copied.

If either case, if the destination folder does not exist it will be created. Note that if the PathToExistingFile mask does not match any file, the destination folder is not created.

This parameter accepts both fully-qualified and relative paths. In addition, folder paths must include a trailing backslash (you can add it using the IncludeTrailingBackSlash method).

RenameOnCollision

Specifies the method behavior in case the file to be created already exists. If RenameOnCollision is True, which is the default value, the method copies the original file to the Copy of <FileName> file in the destination folder. Otherwise, the method overwrites the destination file.

Note: aqFileSystem.CopyFile cannot overwrite files that have the read-only, system or hidden attribute set.

Result Value

True if all the specified files were copied successfully, and False otherwise.

If the PathToExistingFile file was not found, the method returns False. However, if the PathToExistingFile mask that uses wildcards does not match any file, the method returns True.

Remarks

If the method fails to copy the file, TestComplete will post an information message to the test log explaining the cause of the failure.

Example

The following statement creates a backup copy of MyFile.txt in the same folder:

JavaScript, JScript

aqFileSystem.CopyFile("C:\\MyFolder\\MyFile.txt", "C:\\MyFolder\\MyFile.bkp");

Python

aqFileSystem.CopyFile("C:\\MyFolder\\MyFile.txt", "C:\\MyFolder\\MyFile.bkp")

VBScript

Call aqFileSystem.CopyFile("C:\MyFolder\MyFile.txt", "C:\MyFolder\MyFile.bkp")

DelphiScript

aqFileSystem.CopyFile('C:\MyFolder\MyFile.txt', 'C:\MyFolder\MyFile.bkp');

C++Script, C#Script

aqFileSystem["CopyFile"]("C:\\MyFolder\\MyFile.txt", "C:\\MyFolder\\MyFile.bkp");

The following statement copies the MyFile.txt file to another folder:

JavaScript, JScript

aqFileSystem.CopyFile("C:\\MyFolder\\MyFile.txt", "C:\\TempFolder\\");

Python

aqFileSystem.CopyFile("C:\\MyFolder\\MyFile.txt", "C:\\TempFolder\\")

VBScript

Call aqFileSystem.CopyFile("C:\MyFolder\MyFile.txt", "C:\TempFolder\")

DelphiScript

aqFileSystem.CopyFile('C:\MyFolder\MyFile.txt', 'C:\TempFolder\');

C++Script, C#Script

aqFileSystem["CopyFile"]("C:\\MyFolder\\MyFile.txt", "C:\\TempFolder\\");

The following statement copies all text files from the C:\MyFiles folder to C:\TempFolder:

JavaScript, JScript

aqFileSystem.CopyFile("C:\\MyFolder\\*.txt", "C:\\TempFolder\\");

Python

aqFileSystem.CopyFile("C:\\MyFolder\\*.txt", "C:\\TempFolder\\")

VBScript

Call aqFileSystem.CopyFile("C:\MyFolder\*.txt", "C:\TempFolder\")

DelphiScript

aqFileSystem.CopyFile('C:\MyFolder\*.txt', 'C:\TempFolder\');

C++Script, C#Script

aqFileSystem["CopyFile"]("C:\\MyFolder\\*.txt", "C:\\TempFolder\\");

See Also

Working With Files From Scripts
aqFileSystem.MoveFile Method
aqFileSystem.RenameFile Method
aqFileSystem.DeleteFile Method
aqFile.Copy Method
Copy Method
aqFileSystem.CopyFolder Method
aqFileSystem.Exists Method
aqFileSystem.GetCurrentFolder Method
aqFileSystem.SetCurrentFolder Method

Highlight search results