aqFileSystem.MoveFile Method

Applies to TestComplete 15.68, last modified on October 16, 2024

Description

Use the MoveFile method to move one or several files from one folder to another.

Declaration

aqFileSystem.MoveFile(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

The path to the file to be moved. Both fully-qualified and relative paths are acceptable. To move 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 specified a single file (not a mask), this parameter can be either the new file path, or the path to the folder where the file will be moved.

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

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 destination folder already contains a file with the same name. If RenameOnCollision is True (which is the default value), the method moves the source file to the Copy of <FileName> file in the destination folder. Otherwise, the method overwrites the destination file.

Result Value

True if all the specified files were moved 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 move the file, TestComplete will post an information message to the test log explaining the cause of the failure.

Example

The following statement moves a file to another folder:

JavaScript, JScript

aqFileSystem.MoveFile("C:\\MyFiles\\MyFile.txt", "C:\\TempFolder\\");

Python

aqFileSystem.MoveFile("C:\\MyFiles\\MyFile.txt", "C:\\TempFolder\\")

VBScript

Call aqFileSystem.MoveFile("C:\MyFiles\MyFile.txt", "C:\TempFolder\")

DelphiScript

aqFileSystem.MoveFile('C:\MyFiles\MyFile.txt', 'C:\TempFolder\');

C++Script, C#Script

aqFileSystem["MoveFile"]("C:\\MyFiles\\MyFile.txt", "C:\\TempFolder\\");

The following statement uses the aqFileSystem.MoveFile method to rename a file:

JavaScript, JScript

aqFileSystem.MoveFile("C:\\MyFiles\\MyFile.txt", "C:\\MyFiles\\NewFile.txt");

Python

aqFileSystem.MoveFile("C:\\MyFiles\\MyFile.txt", "C:\\MyFiles\\NewFile.txt")

VBScript

Call aqFileSystem.MoveFile("C:\MyFiles\MyFile.txt", "C:\MyFiles\NewFile.txt")

DelphiScript

aqFileSystem.MoveFile('C:\MyFiles\MyFile.txt', 'C:\MyFiles\NewFile.txt');

C++Script, C#Script

aqFileSystem["MoveFile"]("C:\\MyFiles\\MyFile.txt", "C:\\MyFiles\\NewFile.txt");

The following statement moves all text files from one folder to another:

JavaScript, JScript

aqFileSystem.MoveFile("C:\\MyFiles\\*.txt", "C:\\TempFolder\\");

Python

aqFileSystem.MoveFile("C:\\MyFiles\\*.txt", "C:\\TempFolder\\")

VBScript

Call aqFileSystem.MoveFile("C:\MyFiles\*.txt", "C:\TempFolder\")

DelphiScript

aqFileSystem.MoveFile('C:\MyFiles\*.txt', 'C:\TempFolder\');

C++Script, C#Script

aqFileSystem["MoveFile"]("C:\\MyFiles\\*.txt", "C:\\TempFolder\\");

See Also

Working With Files From Scripts
CopyFile Method
RenameFile Method
DeleteFile Method
Move Method
Move Method
MoveFolder Method
Exists Method
GetCurrentFolder Method
SetCurrentFolder Method

Highlight search results