Skip to main content

ExtractFileExt

Function ExtractFileExt( const FileName : string) : string

Example

procedure ScriptEvent(var Value: variant);
begin
Value := ExtractFileExt('C:\Fictional\archive.tar.gz');
// .gz
end;

Usage

ExtractFileExt returns the final extension, including its leading dot, from a file-name string.

Parameters

NameTypeDescription
FileNamestring, constFile-name or path text to inspect.

Returns

The suffix beginning with the last dot after the final recognised path/drive delimiter, or an empty string when no such dot exists.

Behaviour

  • 'report.csv' returns '.csv'.
  • 'archive.tar.gz' returns '.gz'.
  • 'report' returns ''.
  • 'report.' returns '.'.
  • Directory and drive text are not included in the result.

Errors

There is no normal path-content exception. Argument conversion or result allocation can fail through the usual runtime path.

Additional Technical Info

ExtractFileExt returns the final extension parsed from FileName, including its leading dot. It examines only the string and does not require a real file.

The example is source-reviewed and was not executed by the documentation workflow.

Implementation

The Velox wrapper calls installed System.SysUtils.ExtractFileExt. Its Windows implementation finds the last dot, backslash or drive colon. It returns a suffix only if the winning delimiter is a dot; the dot is retained in the returned string.

Edge cases and quirks

  • A dotfile such as '.env' returns '.env'; the whole name is considered the extension.
  • A dot in a directory segment is ignored when a recognised backslash follows it.
  • On the current Windows build, forward slash is not a path delimiter for this routine. Mixed or URL-style paths can therefore treat a dot from an earlier segment as the extension delimiter.
  • No case conversion or validation occurs. '.CSV', spaces and unusual characters are returned exactly.
  • The function does not infer compound extensions such as '.tar.gz'.

Side effects

None.

Performance and concurrency

The routine scans backward and copies at most one suffix, so work is linear in path length. It has no mutable shared state.

Remarks

Compare the result using the case rules required by the receiving system. An extension is a naming convention, not proof of file content or format.

Related entries

External references

Created 2026-07-15