aqFileSystem.GetFileNameWithoutExtension Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the GetFileNameWithoutExtension method to extract the file name (without the extension) from the specified path to a file.

Declaration

aqFileSystem.GetFileNameWithoutExtension(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, which the specified path contains, without the extension.

Example

The code below extracts the name of a file, without the extension, 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.GetFileNameWithoutExtension(sPath);
  
  // Posts the file name to the test log
  Log.Message("The file name is " + sName);
  
}

/*
The routine produces the following output:

The file name is FileName
*/

Python

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

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

VBScript

Sub GetFileNameExample

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

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

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.GetFileNameWithoutExtension(sPath);
  
  // Posts the file name to the test log
  Log.Message('The file name is ' + sName);
  
end;

{
The routine produces the following output:

The file name is FileName
}

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["GetFileNameWithoutExtension"]( sPath );
  
  // Posts the file name to the test log
  Log["Message"]( "The file name is " + sName );
  
}

/*
The routine produces the following output:

The file name is FileName
*/

See Also

Working With Files From Scripts
GetFileName Method

Highlight search results