aqFileSystem.GetFileExtension Method

Applies to TestComplete 12.60, last modified on September 17, 2018

Description

Use the GetFileExtension method to extract the extension from the specified path to a file.

Declaration

aqFileSystem.GetFileExtension(PathToFile)

PathToFile [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

PathToFile

Specifies the path to be processed.

Result Value

A string that holds the extension of the specified file.

Example

The code below gets the extension of the specified file and posts it to the test log.

JavaScript, JScript

function FileExtensionExample()
{

  // Specifies the path to the desired file
  var sPath = "C:\\MyFiles\\MyFolder\\FileName.txt";
  
  // Obtains the file's extension
  var sExtension = aqFileSystem.GetFileExtension(sPath);
  
  // Posts the extension to the test log
  Log.Message(sExtension);
  
}
 
/*
The routine produces the following output:

txt
*/


Python

def FileExtensionExample():
  # Specifies the path to the desired file
  sPath = "C:\\MyFiles\\MyFolder\\FileName.txt"
  # Obtains the file's extension 
  sExtension = aqFileSystem.GetFileExtension(sPath)
  # Posts the extension to the test log
  Log.Message(sExtension)

# The routine produces the following output:
# txt

VBScript

Sub FileExtensionExample

  ' Specifies the path to the desired file
  sPath = "C:\MyFiles\MyFolder\FileName.txt"
  
  ' Obtains the file's extension
  sExtension = aqFileSystem.GetFileExtension(sPath)
  
  ' Posts the extension to the test log
  Log.Message(sExtension)
  
End Sub
 
' The routine produces the following output:
' txt

DelphiScript

function FileExtensionExample;
var sPath, sExtension;
begin

  // Specifies the path to the desired file
  sPath := 'C:\MyFiles\MyFolder\FileName.txt';
  
  // Obtains the file's extension
  sExtension := aqFileSystem.GetFileExtension(sPath);
  
  // Posts the extension to the test log
  Log.Message(sExtension);
  
end;
 
{
The routine produces the following output:

txt
}


C++Script, C#Script

function FileExtensionExample()
{

  // Specifies the path to the desired file
  var sPath = "C:\\MyFiles\\MyFolder\\FileName.txt";
  
  // Obtains the file's extension
  var sExtension = aqFileSystem["GetFileExtension"](sPath);
  
  // Posts the extension to the test log
  Log["Message"]( sExtension );
  
}
 
/*
The routine produces the following output:

txt
*/


See Also

Working With Files From Scripts
aqFileSystem.GetFileName Method
aqFileSystem.GetFileFolder Method
aqFileSystem.GetFileDrive Method

Highlight search results