aqFileSystem.GetRelativePath Method

Applies to TestComplete 14.20, last modified on September 11, 2019

Description

Use the GetRelativePath method to convert the fully qualified path specified by the AbsoluteFileName parameter to a relative path calculated against the folder specified by the CurrentFolder parameter.

Declaration

aqFileSystem.GetRelativePath(CurrentFolderAbsoluteFileName)

CurrentFolder [in]    Required    String    
AbsoluteFileName [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

CurrentFolder

Specifies the fully qualified name of the folder to which the resulting path name should be relative.

The Path parameter may or may not include a trailing backslash (\). You can add a trailing backslash to or remove it from the path by using the IncludeTrailingBackSlash or ExcludeTrailingBackSlash method.

AbsoluteFileName

Specifies the absolute path (either to a file or to a folder) that should be transformed to a relative path.

Result Value

A string that holds the path to the file or folder specified by the AbsoluteFileName parameter relative to CurrentFolder.

Example

The code below specifies the current folder and the fully qualified name of a file, obtains the file's path, which is relative to the current folder, and posts this path to the test log.

JavaScript, JScript

function GetRelativePathExample()
{

  // Specifies the current folder
  var sFolderPath = "C:\\MyFiles\\MyFolder";
  
  // Specifies the fully qualified file name
  var sFilePath = "C:\\Work\\FileName.txt";
  
  // Obtains the file's relative path
  var sRelPath = aqFileSystem.GetRelativePath(sFolderPath, sFilePath);
  
  // Posts the relative path to the test log
  Log.Message(sRelPath);
}

/*
The routine produces the following output:

..\..\Work\FileName.txt
*/

Python

def GetRelativePathExample():
  # Specifies the current folder
  sFolderPath = "C:\\MyFiles\\MyFolder"
  # Specifies the fully qualified file name
  sFilePath = "C:\\Work\\FileName.txt"
  # Obtains the file's relative path
  sRelPath = aqFileSystem.GetRelativePath(sFolderPath, sFilePath)
  # Posts the relative path to the test log
  Log.Message(sRelPath)

# The routine produces the following output:
# ..\..\Work\FileName.txt

VBScript

Sub GetRelativePathExample

  ' Specifies the current folder
  sFolderPath = "C:\MyFiles\MyFolder"
  
  ' Specifies the fully qualified file name
  sFilePath = "C:\Work\FileName.txt"
  
  ' Obtains the file's relative path
  sRelPath = aqFileSystem.GetRelativePath(sFolderPath, sFilePath)
  
  ' Posts the relative path to the test log
  Log.Message(sRelPath)
End Sub

' The routine produces the following output:
' ..\..\Work\FileName.txt

DelphiScript

function GetRelativePathExample;
var sFolderPath, sFilePath, sRelPath;
begin

  // Specifies the current folder
   sFolderPath := 'C:\MyFiles\MyFolder';
  
  // Specifies the fully qualified file name
  sFilePath := 'C:\Work\FileName.txt';
  
  // Obtains the file's relative path
  sRelPath := aqFileSystem.GetRelativePath(sFolderPath, sFilePath);
  
  // Posts the relative path to the test log
  Log.Message(sRelPath);
end;

{
The routine produces the following output:

..\..\Work\FileName.txt
}

C++Script, C#Script

function GetRelativePathExample()
{

  // Specifies the current folder
  var sFolderPath = "C:\\MyFiles\\MyFolder";
  
  // Specifies the fully qualified file name
  var sFilePath = "C:\\Work\\FileName.txt";
  
  // Obtains the file's relative path
  var sRelPath = aqFileSystem["GetRelativePath"]( sFolderPath, sFilePath );
  
  // Posts the relative path to the test log
  Log["Message"]( sRelPath );
}

/*
The routine produces the following output:

..\..\Work\FileName.txt
*/

See Also

Working With Files From Scripts
aqFileSystem.ExpandFileName Method
aqFileSystem.ExpandUNCFileName Method

Highlight search results