Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Path From File Name

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?

like image 768
Nathan Campos Avatar asked Jan 08 '10 21:01

Nathan Campos


People also ask

How do I remove a filename from a path?

The method fileCompinent() is used to remove the path information from a filename and return only its file component. This method requires a single parameter i.e. the file name and it returns the file component only of the file name.

How do I delete a file path in Linux?

To permanently remove a directory in Linux, use either rmdir or rm command: For empty directories, use rmdir [dirname] or rm -d [dirname] For non-empty directories, use rm -r [dirname]

What is the difference between a path and a file name?

A file name is a name a particular inode is called inside a particular directory. A path is some instructions for how to reach an inode from a known point.

What is a filename path?

The set of names required to specify a particular file in a hierarchy of directories is called the path to the file, which you specify as a path name. Path names are used as arguments for commands.


2 Answers

Just add ExtractFileName(FName);

like image 173
fupsduck Avatar answered Sep 25 '22 00:09

fupsduck


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

like image 36
Mason Wheeler Avatar answered Sep 22 '22 00:09

Mason Wheeler