Description
Use the aqFile.Copy
method to copy one or several files to a new location. This method will help you resolve possible file name collisions.
Declaration
aqFile.Copy(PathToExistingFile, PathToNewFile, RenameOnCollision)
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
Specifies 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. In either case, if the destination folder does not exist it will be created. Note that if the PathToExistingFile mask that uses wildcards does not match any files, the destination folder is not created.
The PathToNewFile parameter accepts both fully-qualified and relative paths. In addition, folder paths must include a trailing backslash (you can add it using the aqFileSystem.IncludeTrailingBackSlash
method).
RenameOnCollision
Specifies the method behavior in case the destination file already exists. If RenameOnCollision is True, which is the default value, the method copies the source file to the Copy of <FileName> file in the destination folder. Otherwise, the method overwrites the destination file.
Note: | aqFile.Copy cannot overwrite files that have the read-only, system or hidden attribute set. |
Result Value
True if the file was copied successfully, and False otherwise.
If the PathToExistingFile file was not found, the method returns False. But if the PathToExistingFile mask using wildcards does not match any files, 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
aqFile.Copy("C:\\MyFolder\\MyFile.txt", "C:\\MyFolder\\MyFile.bkp");
Python
aqFile.Copy("C:\\MyFolder\\MyFile.txt", "C:\\MyFolder\\MyFile.bkp")
VBScript
Call aqFile.Copy("C:\MyFolder\MyFile.txt", "C:\MyFolder\MyFile.bkp")
DelphiScript
aqFile.Copy('C:\MyFolder\MyFile.txt', 'C:\MyFolder\MyFile.bkp');
C++Script, C#Script
aqFile["Copy"]("C:\\MyFolder\\MyFile.txt", "C:\\MyFolder\\MyFile.bkp");
The following statement copies the MyFile.txt file to another folder:
JavaScript, JScript
aqFile.Copy("C:\\MyFolder\\MyFile.txt", "C:\\TempFolder\\");
Python
aqFile.Copy("C:\\MyFolder\\MyFile.txt", "C:\\TempFolder\\")
VBScript
Call aqFile.Copy("C:\MyFolder\MyFile.txt", "C:\TempFolder\")
DelphiScript
aqFile.Copy('C:\MyFolder\MyFile.txt', 'C:\TempFolder\');
C++Script, C#Script
aqFile["Copy"]("C:\\MyFolder\\MyFile.txt", "C:\\TempFolder\\");
The following statement copies all text files from the C:\MyFolder folder to C:\TempFolder:
JavaScript, JScript
aqFile.Copy("C:\\MyFolder\\*.txt", "C:\\TempFolder\\");
Python
aqFile.Copy("C:\\MyFolder\\*.txt", "C:\\TempFolder\\")
VBScript
Call aqFile.Copy("C:\MyFolder\*.txt", "C:\TempFolder\")
DelphiScript
aqFile.Copy('C:\MyFolder\*.txt', 'C:\TempFolder\');
C++Script, C#Script
aqFile["Copy"]("C:\\MyFolder\\*.txt", "C:\\TempFolder\\");
See Also
Working With Files From Scripts
aqFile.Create Method
aqFile.Move Method
aqFile.Rename Method
aqFile.Delete Method
aqFile.Exists Method
aqFileSystem.CopyFile Method
Copy Method
aqFileSystem.GetCurrentFolder Method
aqFileSystem.SetCurrentFolder Method