DelphiBasics
MkDir
Procedure
Make a directory System unit
 procedure MkDir(const DirectoryName string);
Description
The MkDir procedure makes a new directory in the current directory.
 
If the directory already exists, an EInOutError exception is thrown.
 
You can avoid such an exception by preventing IO errors using the {$IOChecks Off} compiler directive. You must then check the IOResult value to see the outcome of your IO operation (rememering that use of IOResult resets the value).
Related commands
$IOChecksWhen on, an IO operation error throws an exception
ChDirChange the working drive plus path for a specified drive
CreateDirCreate a directory
GetCurrentDirGet the current directory (drive plus directory)
GetDirGet the default directory (drive plus path) for a specified drive
IOResultHolds the return code of the last I/O operation
RemoveDirRemove a directory
RmDirRemove a directory
SelectDirectoryDisplay a dialog to allow user selection of a directory
SetCurrentDirChange the current directory
ForceDirectoriesCreate a new path of directories
 Download this web site as a Windows program.




 
Example code : Create a directory and then remove it
var
  error : Integer;

begin
  // Try to create a new subdirectory in the current directory
  // Switch off I/O error checking
  {$IOChecks off}
  MkDir('TempDirectory');

  // Did the directory get created OK?
  error := IOResult;
  if error = 0
  then ShowMessage('Directory created OK')
  else ShowMessageFmt('Directory creation failed with error %d',[error]);

  // Delete the directory to tidy up
  RmDir('TempDirectory');
  {$IOChecks on}
end;
Show full unit code
  Directory created OK
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page