aqFileSystem.GetFileName Method

Applies to TestComplete 15.62, last modified on March 19, 2024

Description

Use the GetFileName method to extract only the file name and extension from the specified path to a file.

Declaration

aqFileSystem.GetFileName(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 file name and extension the specified path contains.

Example

The code below retrieves the name and extension of a file from the full path to the file and then posts this name to the test log.

JavaScript, JScript

function GetFileNameExample()
{

  // Specifies the path to the desired file
  var sPath = "C:\\MyFiles\\MyFolder\\FileName.txt";
  
  // Obtains information about the file name
  var sName = aqFileSystem.GetFileName(sPath);
  
  // Posts the file name and extension to the test log
  Log.Message("The file name is " + sName);
  
}

/*
The routine produces the following output:

The file name is FileName.txt
*/

Python

def GetFileNameExample():
  # Specifies the path to the desired file
  sPath = "C:\\MyFiles\\MyFolder\\FileName.txt"
  # Obtains information about the file name 
  sName = aqFileSystem.GetFileName(sPath)
  # Posts the file name and extension to the test log
  Log.Message("The file name is " + sName)

# The routine produces the following output:
# The file name is FileName.txt

VBScript

Sub GetFileNameExample

  ' Specifies the path to the desired file
  sPath = "C:\MyFiles\MyFolder\FileName.txt"
  
  ' Obtains information about the file name
  sName = aqFileSystem.GetFileName(sPath)
  
  ' Posts the file name and extension to the test log
  Log.Message("The file name is " + sName)
  
End Sub

' The routine produces the following output:
' The file name is FileName.txt

DelphiScript

function GetFileNameExample;
var sPath, sName;
begin

  // Specifies the path to the desired file
  sPath := 'C:\MyFiles\MyFolder\FileName.txt';
  
  // Obtains information about the file name
  sName := aqFileSystem.GetFileName(sPath);
  
  // Posts the file name and extension to the test log
  Log.Message('The file name is ' + sName);
  
end;

{
The routine produces the following output:

The file name is FileName.txt
}

C++Script, C#Script

function GetFileNameExample()
{

  // Specifies the path to the desired file
  var sPath = "C:\\MyFiles\\MyFolder\\FileName.txt";
  
  // Obtains information about the file name
  var sName = aqFileSystem["GetFileName"](sPath);
  
  // Posts the file name and extension to the test log
  Log["Message"]("The file name is " + sName);
  
}

/*
The routine produces the following output:

The file name is FileName.txt
*/

See Also

Working With Files From Scripts
GetFileExtension Method
GetFileFolder Method
GetFileDrive Method

Highlight search results