Change the working drive plus path for a specified drive System unit
 procedure ChDir ( const Directory : string ) ;
The ChDir procedure sets the working drive + path values to the supplied Directory.
There are as many working directories as drives on the target machine.
If the directory is invalid, you will get an error such as ElnOutError, and the directory will remain unchanged.
Related commands
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
SetCurrentDir Change the current directory
ForceDirectories Create a new path of directories
 Author links

 Download this web site as a Windows program.

Example code : Getting and setting the directory for the C: drive
  directory : string;

  // Get the directory for the C drive
  GetDir(2, directory);
  ShowMessage('Default C drive directory = '+directory);

  // Set the C directory to this value
  GetDir(2, directory);
  ShowMessage('Default C drive directory = '+directory);

  // Try to set to an invalid value
  GetDir(2, directory);
  ShowMessage('Default C drive directory = '+directory);
Show full unit code
   The following output is representative, and will necessarily vary
   from PC to PC:
   C:\Program Files\Borland\Delphi7\Projects
   C:\Program Files\Borland\Delphi7\Projects
   ElnOutError with error 'Invalid file name'
Delphi Programming Neil Moffatt 2002 - 2020. All rights reserved.  |  Home Page