Description
Use the Copy
method to copy the file, to which the given aqFileInfoObj
object corresponds, to a new location. The method can resolve possible file name collisions that may occur while copying files.
Declaration
aqFileInfoObj.Copy(PathToNewFile, RenameOnCollision)
aqFileInfoObj | An expression, variable or parameter that specifies a reference to an aqFileInfo object | |||
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:
PathToNewFile
The name of the destination file to create or the folder where to copy the file. Both fully-qualified and relative paths are acceptable. If PathToNewFile is a folder path, it must include a trailing backslash (you can add it to the path using the aqFileSystem.IncludeTrailingBackSlash
method).
If the destination folder does not exist, it will be created.
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 underlying file to the Copy of <FileName> file in the destination folder. Otherwise, the method overwrites the destination file.
Note: | aqFileInfo.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.
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 code snippet creates a backup copy of a file in the same folder:
JavaScript, JScript
var fi = aqFileSystem.GetFileInfo("C:\\MyFolder\\MyFile.txt");
fi.Copy("C:\\MyFolder\\MyFile.bkp");
Python
fi = aqFileSystem.GetFileInfo("C:\\MyFolder\\MyFile.txt")
fi.Copy("C:\\MyFolder\\MyFile.bkp")
VBScript
Dim fi
Set fi = aqFileSystem.GetFileInfo("C:\MyFolder\MyFile.txt")
Call fi.Copy("C:\MyFolder\MyFile.bkp")
DelphiScript
var fi;
begin
fi := aqFileSystem.GetFileInfo('C:\MyFolder\MyFile.txt');
fi.Copy('C:\MyFolder\MyFile.bkp');
end;
C++Script, C#Script
var fi = aqFileSystem["GetFileInfo"]("C:\\MyFolder\\MyFile.txt");
fi["Copy"]("C:\\MyFolder\\MyFile.bkp");
The following code copies a file to another folder:
JavaScript, JScript
var fi = aqFileSystem.GetFileInfo("C:\\MyFolder\\MyFile.txt");
fi.Copy("C:\\TempFolder\\");
Python
fi = aqFileSystem.GetFileInfo("C:\\MyFolder\\MyFile.txt")
fi.Copy("C:\\TempFolder\\")
VBScript
Dim fi
Set fi = aqFileSystem.GetFileInfo("C:\MyFolder\MyFile.txt")
Call fi.Copy("C:\TempFolder\")
DelphiScript
var fi;
begin
fi := aqFileSystem.GetFileInfo('C:\MyFolder\MyFile.txt');
fi.Copy('C:\TempFolder\');
end;
C++Script, C#Script
var fi = aqFileSystem["GetFileInfo"]("C:\\MyFolder\\MyFile.txt");
fi["Copy"]("C:\\TempFolder\\");
See Also
Working With Files From Scripts
Rename Method
Move Method
aqFile.Copy Method
aqFileSystem.CopyFile Method