---
url: >-
  /statelake/scripting-reference/functions-and-procedures/file-functions/extractfileext.md
---

# ExtractFileExt

**ExtractFileExt** returns the file name extension of a file path. The input parameter can either be just a filename or a complete file path.

The extension is considered to be anything that includes and follows the rightmost '.' in a file name. The case of each character is not changed.

**Declaration**: Function ExtractFileExt( const FileName : string) : string

A basic example follows.

```pascal
procedure OnMapEvent(var Value:Variant);
begin
  Value := ExtractFileExt(Source.FileCon.CurrentFilename);
end;
```

Therefore:

* ExtractFileExt('abc.txt') returns '.txt'
* ExtractFileExt('abc') returns '', because there is no '.' in the file name
* ExtractFileExt('abc.') returns '.'
* ExtractFileExt('abc...') returns '.'
* ExtractFileExt('abc.ref1.txt') returns '.txt'
* ExtractFileExt('abc.TXT') returns '.TXT'

The following code illustrates this function more completely,

```pascal
procedure ScriptEvent (var Value : variant);
var
  f: string;
begin
  f := 'abc'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc..'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc...'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.a'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.A'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.txt'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.Txt'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.txT'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.TXT'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.ref1.txt'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.ref1.ref2.txt'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
  f := 'abc.exe'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFileExt(f) + '''');
end;
```
