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
ExtractFileExtExtracts the extension part of a full file name
ProcessPathSplit a drive/path/filename string into its constituent parts
 Download this web site as a Windows program.




 
Example code : Renaming Unit1.dcu to Unit1.old
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;
Show full unit code
  Old name = Unit1.dcu
  New name = Unit1.new
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page