ExtractFileDir extracts the drive and directory parts from FileName.
ExtractFileDrive returns the drive portion of a file name/path.
ExtractFilePath returns the drive and directory portions of
a file name.
ExtractFileName extracts the name and extension parts of a file
name.
ExtractFileExt returns the extension portions of a file name.
ExpandFileName returns the full path name for a chosen file
name.
Example:
This example came from the Directory,
Files and Drives web page.
procedure TForm1.Button1Click(Sender: TObject);
var NPath : string;
begin
OpenDialog1.InitialDir := NPath;
if OpenDialog1.Execute then
begin
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
NPath := ExtractFilePath(OpenDialog1.FileName);
end;
Label1.Caption := NPath;
Label2.Caption := ExtractFileName(OpenDialog1.FileName);
Caption := Format('%s - %s', [ExtractFileName(OpenDialog1.FileName),
Application.Title]);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Label1.Caption := ExtractFileDrive(OpenDialog1.FileName);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Label1.Caption := ExtractFileDir(OpenDialog1.FileName);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Label1.Caption := ExtractFileExt(OpenDialog1.FileName);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Memo1.Lines.Add(ExpandFileName(Edit1.Text));
end;
If I typed James.txt into Edit1 then this would be the result on my computer.
C:\Delphi5\AProjects\examples\DrawdeskTopCanvas\James.txt
This gives us the path that I was currently working in and ExpandFileName added the filename that was typed into Edit1.
The Delphi help file states:
ExpandFileName does not verify that the resulting fully qualified path
name refers to an existing file, or even that the resulting path exists.