6

I'm developing a program that needs to parse the file name into a TTextField. How to remove the file extension I've already know(or think that I can do like this):

var
  FName: String;
  FPath: String;

begin
  FPath := OpenDialog1.FileName;
  FName := ChangeFileExt(FPath, '');
end;

But how can I remove the file path from FName?

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

3 Answers3

18

Just add ExtractFileName(FName);

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
fupsduck
  • 3,129
  • 1
  • 19
  • 18
7

Take a look at SysUtils.ExtractFileName. I think that's what you're looking for.

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
0

In newer Delphi versions there is also TPath.GetFileName from System.IOUtils

johnny
  • 657
  • 7
  • 18