Home  |  Delphi .net Home  |  System.IO.DirectoryInfo  |  GetDirectories Method
  
GetDirectories  
Method  
Gets the Directories (folders) in the specified Directory
DirectoryInfo Class
System.IO NameSpace
CF1.  Function GetDirectories ( PathString : String ) : Array of DirectoryInfo;
CF2.  Function GetDirectories ( PathString : String; Filter : String ) : Array of DirectoryInfo;
CF : Methods with this mark are Compact Framework Compatible
Description
The GetDirectories method returns an array of DirectoryInfo objects for all the sub-directories of the current folder. Optionally, this list may be limited by the Filter string.
 
The array size is dynamically set by this method.
 
This filter string may contain valid directory name characters, but may not have consecutive . characters. Use * wildcard to represent a sequence of 0 or more characters, and ? to represent a single character.
Microsoft MSDN Links
System.IO
System.IO.DirectoryInfo
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
An example of the 1st syntax
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  DirInfo  : System.IO.DirectoryInfo;
  Folders  : Array of DirectoryInfo;
  i        : Integer;

begin
  // Create our directory info object
  DirInfo := System.IO.DirectoryInfo.Create('C:\Base');

  // And some sub-folders
  DirInfo.CreateSubdirectory('First');
  DirInfo.CreateSubdirectory('Second');
  DirInfo.CreateSubdirectory('Third');

  // List the folders under C:\Base
  Folders := DirInfo.GetDirectories;

  for i := 0 to Length(Folders)-1 do
    Console.WriteLine(Folders[i].ToString);

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

  Console.Readline;
end.
   First
   Second
   Third
Example of the second syntax
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  DirInfo  : System.IO.DirectoryInfo;
  Folders  : Array of DirectoryInfo;
  i        : Integer;

begin
  // Create our directory info object
  DirInfo := System.IO.DirectoryInfo.Create('C:\Base');

  // And some sub-folders
  DirInfo.CreateSubdirectory('First');
  DirInfo.CreateSubdirectory('Second');
  DirInfo.CreateSubdirectory('Third');

  // List the folders under C:\Base containing 'r'
  Folders := DirInfo.GetDirectories('*r*');

  for i := 0 to Length(Folders)-1 do
    Console.WriteLine(Folders[i].ToString);

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

  Console.Readline;
end.
   First
   Third
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author