DelphiBasics
SetCurrentDir
Function
Change the current directory SysUtils unit
 function SetCurrentDir ( const Dir : string ) : Boolean;
Description
The SetCurrentDir function sets the current directory to Dir, returning True if successful.
 
If the directory does not exist, then getLAstError can be used to get the error code.
Related commands
ChDir Change the working drive plus path for a specified drive
CreateDir Create a directory
GetCurrentDir Get the current directory (drive plus directory)
GetDir Get the default directory (drive plus path) for a specified drive
MkDir Make a directory
RemoveDir Remove a directory
RmDir Remove a directory
SelectDirectory Display a dialog to allow user selection of a directory
ForceDirectories Create a new path of directories
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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




 
Example code : Show set and re-show the current directory
// 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 SetCurrentDir 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);

begin
  // Show the current directory
  ShowMessage('Current directory = '+GetCurrentDir);

  // Change this value
  SetCurrentDir('C:\Program Files');

  // Show the current directory again
  ShowMessage('Current directory = '+GetCurrentDir);
end;
 
end.
Hide full unit code
   Current directory = C:\Program Files\Borland\Delphi7\Projects
   Current directory = C:\Program Files
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page