Home  |  Delphi .net Home  |  System.IO.DirectoryInfo  |  CreateSubDirectory Method
CreateSubDirectory  
Method  
Creates a SubDirectory (folder) within the current directory
DirectoryInfo Class
System.IO NameSpace
CF1.  Function CreateSubDirectory ( SubFolder : String; ) : DirectoryInfo;
CF : Methods with this mark are Compact Framework Compatible
Description
The CreateSubDirectory method cerates a new SubFolder within the current folder. A DirectoryInfo object is returned for this subfolder, allowing recursive subfolder processing.
Microsoft MSDN Links
System.IO
System.IO.DirectoryInfo
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  DirInfo   : System.IO.DirectoryInfo;
  Base      : String;
  SubFolder : String;

begin
  Base      := 'C:\Base';
  SubFolder := 'SubFolder';

  // Create a DirectoryInfo object for this Base folder
  DirInfo := System.IO.DirectoryInfo.Create(Base);

  // Create the Base folder
  DirInfo.&Create;   // Note : must use & to differentiate from reserved word

  // And create a sub folder
  DirInfo.CreateSubDirectory(SubFolder);

  if System.IO.Directory.Exists(Base+'\'+SubFolder)
  then Console.WriteLine('{0} now exists', Base+'\'+SubFolder)
  else Console.WriteLine('{0} does not exist', Base+'\'+SubFolder);

  // Now delete this nest of folders
  DirInfo.Delete(true);

  Console.Readline;
end.
Show full unit code
  C:\Base\SubFolder now exists
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author