1. Home
  2. Computing & Technology
  3. Delphi Programming
Delphi for .NET FCL Examples Reference
DirectoryInfo class namespace
System.IO
Declaration
type DirectoryInfo = class sealed(FileSystemInfo)
Description
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories.
Example
The following example demonstrates some of the main members of the DirectoryInfo class:
program System_IO_DirectoryInfo;

{$APPTYPE CONSOLE}
{$AUTOBOX ON}

uses
  System.IO;

type
  TestDirectoryInfo = class
  public
    class procedure Main;
  end;

{ TestDirectoryInfo }

class procedure TestDirectoryInfo.Main;
var
  di: DirectoryInfo;
begin
  // Specify the directories you want to manipulate
  di := DirectoryInfo.Create('c:\MyDir');
  try
    // Determine whether the directory exists
    if di.Exists then
    begin
      Console.WriteLine('That path exists already.');
      Exit;
    end;

    // Try to create the directory
    di.&Create;
    Console.WriteLine('The directory was 
                       created successfully.');

    // Delete the directory.
    di.Delete;
    Console.WriteLine('The directory was 
                       deleted successfully.');
  except
    on e: Exception do
      Console.WriteLine('The process failed: {0}', e.ToString);
  end;
end;


//test program
begin
  TestDirectoryInfo.Main;
end.
Example output
The directory was created successfully.
The directory was deleted successfully.

Looking for Delphi for .NET demos / source code samples? Look no further, Delphi for .NET FCL Examples Reference is what you are searching for!

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.