DelphiBasics
ForceDirectories
Function
Create a new path of directories SysUtils unit
 function ForceDirectories(const Path string):Boolean;
Description
The ForceDirectories function creates one or more nested directories specified by the Path.
 
If the create succeeded, then True is returned, otherwise the error can be obtained using GetLastError.
Related commands
CreateDirCreate a directory
GetCurrentDirGet the current directory (drive plus directory)
GetDirGet the default directory (drive plus path) for a specified drive
MkDirMake a directory
ChDirChange the working drive plus path for a specified drive
RmDirRemove a directory
RemoveDirRemove a directory
SelectDirectoryDisplay a dialog to allow user selection of a directory
SetCurrentDirChange the current directory
 Download this web site as a Windows program.




 
Example code : Create a new path on the C drive
begin
  // Try to create a new nested directory in the current directory
  if CreateDir('C:\NonExistantDir\TestDir')
  then ShowMessage('New directory added OK')
  else ShowMessage('New directory add failed with error : '+
                   IntToStr(GetLastError));

  // Now force it to create this directory
  if ForceDirectories('C:\NonExistantDir\TestDir')
  then ShowMessage('New directory added OK')
  else ShowMessage('New directory add failed with error : '+
                   IntToStr(GetLastError));
end;
Show full unit code
  New directory add failed with error 3
  New directory added OK
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page