Home  |  Delphi .net Home  |  System.IO.DirectoryInfo  |  Create Method
Create  
Method  
Creates a new Directory or nest of Directories for the current Directory Path
DirectoryInfo Class
System.IO NameSpace
CF1.  Procedure Create ( ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The hierarchy of directories (folders) in the current path are checked against the actual machine file system. New directories are created so that the full path is now valid.
Notes
Important : because Create is a reserved word in Delphi, you must prefix it by an & to tell Delphi to treat it as a method name.
Microsoft MSDN Links
System.IO
System.IO.DirectoryInfo
 
 
Creating a nest of two new directories and then deleting them
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  DirInfo : System.IO.DirectoryInfo;
  Path    : String;

begin
  Path := 'C:\Dir1\Dir2';

  if System.IO.Directory.Exists(Path)
  then Console.WriteLine('{0} exists', Path)
  else Console.WriteLine('{0} does not exist', Path);

  // Create a DirectoryInfo object for this nest of 2 folders
  DirInfo := System.IO.DirectoryInfo.Create(Path);

  // Create the nest of 2 new folders
  DirInfo.&Create;

  if System.IO.Directory.Exists(Path)
  then Console.WriteLine('{0} exists', Path)
  else Console.WriteLine('{0} does not exist', Path);

  // Now delete this nest of folders
  DirInfo.Delete;

  Console.Readline;
end.
Show full unit code
  C:Dir1Dir2 does not exist
  C:Dir1Dir2 exists
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author