2009. szeptember 30., szerda

Get only file name


Problem/Question/Abstract:

How to get only file name (without extension) ?  Example: If i have: c:\test\other\anyfile.doc  and i want get only "anyfile".

Answer:

Solve 1:

function FileName(Value: string): string;
begin
  Result := ExtractFileName(Value);
  if ExtractFileExt(Value) <> '' then
    Result := Copy(ExtractFileName(Value), 1,
      Pos(ExtractFileExt(Value), ExtractFileName(Value)) - 1);
end;


Solve 2:

function FileName(Value: string): string;
begin
  Result := ChangeFileExt(ExtractFileName(Value), '');
end;

Nincsenek megjegyzések:

Megjegyzés küldése