DelphiBasics
ProcessPath
Procedure
Split a drive/path/filename string into its constituent parts FileCtrl unit
 procedure ProcessPath ( const FullName : string; var Drive : Char; var Dir : string; var FileName : string ) ;
Description
The ProcessPath procedure splits a full file name FullName into its constituent Drive, Dir and FileName parts.
Related commands
ExtractFileDir Extracts the dir part of a full file name
ExtractFileDrive Extracts the drive part of a full file name
ExtractFileExt Extracts the extension part of a full file name
ExtractFileName Extracts the name part of a full file name
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
Example code : Ask the user for a file name, and show the constituent parts
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  FileCtrl,   // Unit containing the ProcessPath command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  selectedFile   : string;
  drive          : char;
  path, fileName : string;

begin
  // Ask the user to select a file
  if PromptForFileName(selectedFile)
  then
  begin
    // Display this full file/path value
    ShowMessage('Selected file = '+selectedFile);

    // Split this full file/path value into its constituent parts
    ProcessPath(selectedFile, drive, path, fileName);
    ShowMessage('drive = '+drive);
    ShowMessage('path = '+path);
    ShowMessage('fileName = '+fileName);
  end;
end;
 
end.
Hide full unit code
   { The user selects C:\Files\data.txt and hits OK }
  
   Selected file = C:\Files\data.txt
   drive = C
   path = \Files
   filename = data.txt
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page