Home  |  Delphi .net Home  |  System.IO.Directory  |  GetFileSystemEntries Method
  
GetFileSystemEntries  
Method  
Gets the Files and Directories (folders) in the specified Directory
Directory Class
System.IO NameSpace
CF1.  Function GetFileSystemEntries ( PathString : String ) : Array of String; Static;
CF2.  Function GetFileSystemEntries ( PathString : String; Filter : String ) : Array of String; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
The GetFileSystemEntries method returns an array of strings that hold the absolute paths of the files and directories in the specified absolute or relative PathString directory. 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 file 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.
Notes
Static methods are not methods of an object - they are simply class functions or procedures available at any time.
Microsoft MSDN Links
System.IO
System.IO.Directory
 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
  Path  : String;
  Files : Array of String;
  i     : Integer;

begin
  // Get the current folder
  Path := System.IO.Directory.GetCurrentDirectory;

  // And then get its parent folder
  Path := System.IO.Directory.GetParent(Path).Tostring;

  Console.WriteLine('Files and folders in : ' + Path + ' :');
  Console.WriteLine;

  // Get all files and folders in this folder
  Files := System.IO.Directory.GetFileSystemEntries(Path);

  // Display the files - just the file names that is
  for i := 0 to Length(Files)-1 do
    Console.WriteLine(System.IO.Path.GetFileName(Files[i]));

  Console.Readline;
end.
   Files and folders in : C:\Documents and Settings\Neil\My Documents :
  
   Borland Studio Projects
   Corel User Files
   LizaJet Packages
   My Albums
   My Diagrams
   My eBooks
   My Library
   My Music
   My Pictures
   My PSP8 Files
   My Received Files
   My Videos
   New Folder
   Nursing Agency Solutions
   SimCity 4
   000000.gif
   Adobe.pdf
   Backup
   bb01_1024.jpg
   BB021024.jpg
   bb09_1024.jpg
   C drive fragmentation before Diskeeper.txt
   D drive fragmentation before Diskeeper.txt
   Default.rdp
   desktop.ini
   Diary.csv
   HospitalCodeMapping.csv
   HospitalCodes.csv
   Hospitals.rtf
   Hospitals.txt
   Invoice Test.RTF
   Invoice Test.TXT
   KeyGenerator Screenshot.PNG
   Let to Morris-Party Wall.bmp
   Menu page 1.ppp
   Menu page 2.ppp
   New Invoice Print.RTF
   New.rtf
   ProjectSpellingCorrector190204.cfg
   ProjectSpellingCorrector190204.dpr
   ProjectSpellingCorrector190204.exe
   ProjectSpellingCorrector190204.res
   RPT0001.HTM
   RPT0002.HTM
   RPT0003.HTM
   Test.html
   Test.pdf
   Test.RTF
   Thumbs.db
   Web.html
   Weekly.csv
An example of the 2nd syntax
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Path  : String;
  Files : Array of String;
  i     : Integer;

begin
  // Get the current folder
  Path := System.IO.Directory.GetCurrentDirectory;

  // And then get its parent folder
  Path := System.IO.Directory.GetParent(Path).Tostring;

  Console.WriteLine('M* Files and folders in : ' + Path + ' :');
  Console.WriteLine;

  // Get all files and folders in this folder starting with M
  Files := System.IO.Directory.GetFileSystemEntries(Path, 'M*');

  // Display the files - just the file names that is
  for i := 0 to Length(Files)-1 do
    Console.WriteLine(System.IO.Path.GetFileName(Files[i]));

  Console.Readline;
end.
   M* Files and folders in : C:\Documents and Settings\Neil\My Documents :
  
   My Albums
   My Diagrams
   My eBooks
   My Library
   My Music
   My Pictures
   My PSP8 Files
   My Received Files
   My Videos
   Menu page 1.ppp
   Menu page 2.ppp
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author