You can use parse function to extract what you want from the directory and
function Parse(Char, S: string; Count: Integer): string;
var
I: Integer;
T: string;
begin
if S[Length(S)] <> Char then
S := S + Char;
for I := 1 to Count do
begin
T := Copy(S, 0, Pos(Char, S) - 1);
S := Copy(S, Pos(Char, S) + 1, Length(S));
end;
Result := T;
end;
CALL:
for ex.you want the first section of the dirname separated by '\' under windows :
{$IFDEF WINDOWS}
F1 := Parse('\', dirname ,1)
{$ENDIF}
you can use this function to get different parts of the dirname and do what you want