aqFileSystem.GetShortPathName Method

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

Description

Use the GetShortPathName method to obtain the shortened version of the specified path. In short paths, the names of files and folders do not exceed 8 characters, and the extensions are no longer than 3 characters. This naming convention was adopted in MS-DOS.

Declaration

aqFileSystem.GetShortPathName(LongPath)

LongPath [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

LongPath

Specifies the fully qualified path to an existing file or folder.

If LongPath specifies a folder path, it 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.

Result Value

A string that holds the specified path converted to the short form.

Remarks

If the specified file or folder does not exist, the method raises an exception. To verify whether the specified file or folder exists, use the Exists method.

Example

The code below obtains the short path to the specified file and posts the path to the test log.

JavaScript, JScript

function ShortPathExample()
{

  // Specifies the fully qualified file name
  var sPath = "C:\\FolderName\\FileLongName.txt";
  
  // Obtains the file's short path
  var sShortPath = aqFileSystem.GetShortPathName(sPath);
  
  // Posts the file's short path to the test log
  Log.Message("The file's short path is: " + sShortPath);
  
}

/*
The routine produces the following output:

The file's short path is: C:\FOLDER~1\FILELO~1.TXT
*/

Python

def ShortPathExample():
  # Specifies the fully qualified file name
  sPath = "C:\\FolderName\\FileLongName.txt"
  # Obtains the file's short path
  sShortPath = aqFileSystem.GetShortPathName(sPath)
  # Posts the file's short path to the test log
  Log.Message("The file's short path is: " + sShortPath)

# The routine produces the following output:
# The file's short path is: C:\FOLDER~1\FILELO~1.TXT

VBScript

Sub ShortPathExample

  ' Specifies the fully qualified file name
  sPath = "C:\FolderName\FileLongName.txt"
  
  ' Obtains the file's short path
  sShortPath = aqFileSystem.GetShortPathName(sPath)
  
  ' Posts the file's short path to the test log
  Log.Message("The file's short path is: " + sShortPath)
  
End Sub

' The routine produces the following output:
' The file's short path is: C:\FOLDER~1\FILELO~1.TXT

DelphiScript

function ShortPathExample;
var sPath, sShortPath;
begin

  // Specifies the fully qualified file name
  sPath := 'C:\FolderName\FileLongName.txt';
  
  // Obtains the file's short path
  sShortPath := aqFileSystem.GetShortPathName(sPath);
  
  // Posts the file's short path to the test log
  Log.Message('The file''s short path is: ' + sShortPath);
  
end;

{
The routine produces the following output:

The file's short path is: C:\FOLDER~1\FILELO~1.TXT
}

C++Script, C#Script

function ShortPathExample()
{

  // Specifies the fully qualified file name
  var sPath = "C:\\FolderName\\FileLongName.txt";
  
  // Obtains the file's short path
  var sShortPath = aqFileSystem["GetShortPathName"](sPath);
  
  // Posts the file's short path to the test log
  Log["Message"]("The file's short path is: " + sShortPath);
  
}

/*
The routine produces the following output:

The file's short path is: C:\FOLDER~1\FILELO~1.TXT
*/

See Also

Working With Files From Scripts
GetRelativePath Method
ExpandFileName Method

Highlight search results