Copy Method

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

Use the Copy method to copy the folder, to which the given aqFolderInfoObj object corresponds, from one location to another. The method can resolve possible name collisions that may occur while copying folders.

Declaration

aqFolderInfoObj.Copy(NewPath, RenameOnCollision)

aqFolderInfoObj An expression, variable or parameter that specifies a reference to an aqFolderInfo object
NewPath [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:

NewPath

The path to the destination folder to which the given folder will be copied along with its contents. Both fully-qualified and relative paths are acceptable. This path may or may not include a trailing backslash.

RenameOnCollision

Specifies the method behavior in case the NewPath folder already contains a subfolder with the same name as the given folder. If RenameOnCollision is True (which is the default value), the method creates the Copy of <FolderName> subfolder in the NewPath folder and copies the source folder’s contents to that subfolder. Otherwise, the method copies the folder contents to the existing destination subfolder replacing the files having the same name.

Result Value

True if the folder was copied successfully, and False otherwise.

Remarks

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

Example

The code below copies the MyFiles folder and all its subfolders to the C:\Work folder.

JavaScript, JScript

function CopyingFolder()
{

  // Specifies the path to the desired folder
  var sPath = "C:\\Temp\\MyFiles";
  
  // Specifies the new path to the folder
  var sNewPath = "C:\\Work\\";
  
  // Obtains information about the MyFiles folder
  var FolInfo = aqFileSystem.GetFolderInfo(sPath);
  
  // Copies the folder to another location
  FolInfo.Copy(sNewPath);
  
}

Python

def CopyingFolder():
  # Specifies the path to the desired folder
  sPath = "C:\\Work\\MyFiles"
  # Specifies the new path to the folder
  sNewPath = "C:\\Work\\"
  # Obtains information about the MyFiles folder
  FolInfo = aqFileSystem.GetFolderInfo(sPath)
  # Copies the folder to another location
  FolInfo.Copy(sNewPath)

VBScript

Sub CopyingFolder

  ' Specifies the path to the desired folder
  sPath = "C:\Temp\MyFiles"
  
  ' Specifies the new path to the folder
  sNewPath = "C:\Work\"
  
  ' Obtains information about the MyFiles folder
  Set FolInfo = aqFileSystem.GetFolderInfo(sPath)
  
  ' Copies the folder to another location
  FolInfo.Copy(sNewPath)
  
End Sub

DelphiScript

function CopyingFolder;
var sPath, sNewPath, FolInfo;
begin

  // Specifies the path to the desired folder
  sPath := 'C:\Temp\MyFiles';
  
  // Specifies the new path to the folder
  sNewPath := 'C:\Work\';
  
  // Obtains information about the MyFiles folder
  FolInfo := aqFileSystem.GetFolderInfo(sPath);
  
  // Copies the folder to another location
  FolInfo.Copy(sNewPath);
  
end;

C++Script, C#Script

function CopyingFolder()
{

  // Specifies the path to the desired folder
  var sPath = "C:\\Temp\\MyFiles";
  
  // Specifies the new path to the folder
  var sNewPath = "C:\\Work\\";
  
  // Obtains information about the MyFiles folder
  var FolInfo = aqFileSystem["GetFolderInfo"](sPath);
  
  // Copies the folder to another location
  FolInfo["Copy"]( sNewPath );
  
}

See Also

Working With Files From Scripts
Rename Method
Move Method
CopyFolder Method
GetCurrentFolder Method
SetCurrentFolder Method

Highlight search results