aqFileSystem.RenameFolder Method

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

Description

Use the RenameFolder method to change the name of a folder or to move the folder to another folder.

Declaration

aqFileSystem.RenameFolder(OldPath, NewPath)

OldPath [in]    Required    String    
NewPath [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

OldPath

Specifies the path to the folder to be renamed or moved. Both fully-qualified and relative paths are acceptable.

This path should not end with a trailing backslash. To remove it, you can use the ExcludeTrailingBackSlash method.

NewPath

Specifies a new path to the folder. This parameter accepts both fully-qualified and relative paths.

If this path ends with a backslash, the method will move the folder that is specified by the OldPath parameter to the folder that is specified by the NewPath parameter.

If NewPath does not end with a backslash, the method will rename the OldPath folder.

Result Value

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

Remarks

If the specified folder was not found, the method raises an exception. To verify whether the folder exists, use the Exists method.

The method’s functionality depends on whether the NewPath path ends with a backslash (see above). To remove the trailing backslash, use the ExcludeTrailingBackSlash method.

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

Example

The examples below demonstrate how you can use the RenameFolder method to rename and move the desired folders.

The code below shows how you can use the method to rename a folder.

JavaScript, JScript

function RenameFolderExample()
{
 var OldPath = "C:\\MyFiles\\Folder1";
 var NewPath = "C:\\MyFiles\\Folder2";
 
 // Renames the file
 aqFileSystem.RenameFolder(OldPath, NewPath);
}

Python

def RenameFolderExample():
  OldPath = "C:\\MyFiles\\Folder1"
  NewPath = "C:\\MyFiles\\Folder2"
  # Renames the file
  aqFileSystem.RenameFolder(OldPath, NewPath)

VBScript

Sub RenameFolderExample

 OldPath = "C:\MyFiles\Folder1"
 NewPath = "C:\MyFiles\Folder2"
 
 ' Renames the folder
 Call aqFileSystem.RenameFolder(OldPath, NewPath)

End Sub

DelphiScript

function RenameFolderExample;
var OldPath, NewPath;
begin

 OldPath := 'C:\MyFiles\Folder1';
 NewPath := 'C:\MyFiles\Folder2';
 
 // Renames the file
 aqFileSystem.RenameFolder(OldPath, NewPath);

end;

C++Script, C#Script

function RenameFolderExample()
{
 var OldPath = "C:\\MyFiles\\Folder1";
 var NewPath = "C:\\MyFiles\\Folder2";
 
 // Renames the file
 aqFileSystem["RenameFolder"](OldPath, NewPath);
}

The code below shows how you can use the method to move a folder.

JavaScript, JScript

function MoveFolderExample()
{
 var OldPath = "C:\\MyFiles\\Folder1";
 var NewPathMove = "C:\\NewFolder\\";
 
 // Moves the Folder1 folder from the MyFiles folder to NewFolder
 aqFileSystem.RenameFolder(OldPath, NewPathMove);
 
}

Python

def MoveFolderExample():
  OldPath = "C:\\MyFiles\\Folder1"
  NewPathMove = "C:\\NewFolder\\"
  # Moves the Folder1 folder from the MyFiles folder to NewFolder
  aqFileSystem.RenameFolder(OldPath, NewPathMove)

VBScript

Sub MoveFolderExample

 OldPath = "C:\MyFiles\Folder1"
 NewPathMove = "C:\NewFolder\"
 
 ' Moves the Folder1 folder from the MyFiles folder to NewFolder
 Call aqFileSystem.RenameFolder(OldPath, NewPathMove)


End Sub

DelphiScript

function MoveFolderExample;
var OldPath, NewPathMove;
begin

 OldPath := 'C:\MyFiles\Folder1';
 NewPathMove := 'C:\NewFolder\';
 
 // Moves the Folder1 folder from the MyFiles folder to NewFolder
 aqFileSystem.RenameFolder(OldPath, NewPathMove);
 
end;

C++Script, C#Script

function MoveFolderExample()
{
 var OldPath = "C:\\MyFiles\\Folder1";
 var NewPathMove = "C:\\NewFolder\\";
 
 // Moves the Folder1 folder from the MyFiles folder to NewFolder
 aqFileSystem["RenameFolder"](OldPath, NewPathMove);
 
}

See Also

Working With Files From Scripts
Exists Method
MoveFolder Method
CopyFolder Method
DeleteFolder Method

Highlight search results