Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

ExtractFilePath

unit
Sysutils
category
file name utilities

declaration
function ExtractFilePath(const S: FullFileName): string;

description
Returns the drive and directory parts of a string containing full path and file name.

ExtractFilePath resuls is the leftmost characters of FullFileName, up to and including the colon or backslash (\) that separates the path information from the name and extension. If FullFullFileName contatins no directory or drive information, the result is FullFileName empty.

example
//This example copies a specified file 
//into the same directory as the application.

procedure CopyApplicationTo(const AnotherFileName : string);
var
  NewFileName: string;
  Msg: string;
  NewFile: TFileStream;
  OldFile: TFileStream;
begin
  NewFileName := ExtractFilePath(Application.ExeName) + 
                 ExtractFileName(AnotherFileName);
  Msg := Format('Copy %s to %s?', [AnotherFileName, NewFileName]);
  if MessageDlg(Msg, mtCustom, mbOKCancel, 0) = mrOK then
  begin
    OldFile := TFileStream.Create(AnotherFileName, 
                                  fmOpenRead or fmShareDenyWrite);
    try
      NewFile := TFileStream.Create(NewFileName, 
                                    fmCreate or fmShareDenyRead);
      try
        NewFile.CopyFrom(OldFile, OldFile.Size);
      finally
        FreeAndNil(NewFile);
      end;
    finally
      FreeAndNil(OldFile);
    end;
  end;
end;

in real code
Searching for Files
Stop. This is the one and only solution to file searching. Use Delphi to find any file in any directory and/or subdirectory that match a certain mask. Start searching.

Building a mp3 player
See how to build a full-blown mp3 player with Delphi in just a few seconds. Even more: get the ID3 tag information from a mp3 file and change it!

see also
ExtractFileDir, ExtractFileExt, ExtractFileDrive, ExtractFileName, ProcessPath, ParamStr,


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.