Description |
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 |
|
|
|
Example code : Getting and setting the directory for the C: drive |
// 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 // The System unit does not need to be defined 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
directory : string;
begin // Get the directory for the C drive
GetDir(2, directory);
ShowMessage('Default C drive directory = '+directory);
// Set the C directory to this value
ChDir(directory);
GetDir(2, directory);
ShowMessage('Default C drive directory = '+directory);
// Try to set to an invalid value
ChDir('C:Bad/Path/Value');
GetDir(2, directory);
ShowMessage('Default C drive directory = '+directory);
end; end.
|
Hide 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'
|
|