Skip to content

Extract file extension ​

ts
function ExtractExt(fileName: string): string;

Returns the file extension (including the dot) from any file name or path. If the file has no extension, returns an empty string.

Parameters ​

NameTypeDescription
fileNamestringFile name or path to extract from.

Returns ​

A string containing the file extension, including the dot (e.g., ".txt").

NOTE

If the file has no extension, an empty string is returned. For files with multiple dots, only the last segment is considered the extension.

Example ​

ts
var res = ExtractExt('/docs/sheets/budget.xlsx');
// res will be ".xlsx"