The ExtractFilePath function returns the drive and file path portion of a file path which includes a filename.

The value returned includes the trailing backslash (\) at the end of the path, but a blank string is returned if there is no drive or directory present in the input parameter.

Declaration: Function ExtractFilePath( const FileName : string) : string

The basic example follows.

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

A more detailed set of examples follow.

procedure ScriptEvent (var Value : variant);
var
f: string;
begin
f := 'abc.exe'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFilePath(f) + '''');
f := 'abc.ref1.txt'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFilePath(f) + '''');
f := '\abc.ref1.TXT'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFilePath(f) + '''');
f := 'C:\xyzabc.1234.exe'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFilePath(f) + '''');
f := 'C:\MyData\MyFiles\abc.exe'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFilePath(f) + '''');
f := '\MyDrive\MyData\MyFiles\abc.ref1.ref2.txt'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFilePath(f) + '''');
f := 'D:\MyData\MyFiles\TheDocumentAbc.TXT'; LogInfo('ExtractFileExt(''' + f + ''') -> ''' + ExtractFilePath(f) + '''');
LogInfo('');
end;

This code returns the following log entries.

image-20240107-232953.png