DelphiBasics
ChangeFileExt
Function
Change the extension part of a file name SysUtils unit
 function ChangeFileExt ( const FileName, Extension : string ) : string;
Description
The ChangeFileExt function changes the Extension value of a file FileName, returning the new value as a string.
Related commands
ExtractFileExt Extracts the extension part of a full file name
ProcessPath Split a drive/path/filename string into its constituent parts
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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




 
Example code : Renaming Unit1.dcu to Unit1.old
// 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
  SysUtils,   // Unit containing the ChangeFileExt 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
  oldName, newName : string;

begin
  // Try to rename the current Unit1.dcu to Uni1.old
  oldName := 'Unit1.dcu';
  newName := ChangeFileExt(oldName, '.new');

  // Show the old and new values
  ShowMessage('Old name = '+oldName);
  ShowMessage('New name = '+newName);
end;
 
end.
Hide full unit code
   Old name = Unit1.dcu
   New name = Unit1.new
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page