Get only file name (Views: 30)
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; |