Home  |  Delphi .net Home  |  System.IO.DirectoryInfo  |  GetFileSystemInfos Method
GetFileSystemInfos  
Method  
Gets information for files in the current Directory
DirectoryInfo Class
System.IO NameSpace
CF1.  Function GetFileSystemInfos ( ) : Array of FileSystemInfo ;
CF2.  Function GetFileSystemInfos ( Filter : String; ) : Array of FileSystemInfo;
CF : Methods with this mark are Compact Framework Compatible
Description
The GetFileSystemInfos method returns an array of FileSystemInfo objects for all the files in the current 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.
Microsoft MSDN Links
System.IO
System.IO.DirectoryInfo
 
 
An example of the 1st syntax
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  DirInfo : System.IO.DirectoryInfo;
  Path  : String;
  Files : Array of FileSystemInfo;
  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;

  // Create our directory info object for this parent folder
  DirInfo := System.IO.DirectoryInfo.Create(Path);

  // Get the files and folders in this folder
  Console.WriteLine('Files in : ' + Path + ' :');
  Console.WriteLine;

  Files := DirInfo.GetFileSystemInfos;

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

  Console.Readline;
end.
Show full unit code
  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
  DirInfo : System.IO.DirectoryInfo;
  Path  : String;
  Files : Array of FileSystemInfo;
  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;

  // Create our directory info object for this parent folder
  DirInfo := System.IO.DirectoryInfo.Create(Path);

  // Get the files and folders in this folder startnig with 'M'
  Console.WriteLine('M* Files in : ' + Path + ' :');
  Console.WriteLine;

  Files := DirInfo.GetFileSystemInfos('M*');

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

  Console.Readline;
end.
Show full unit code
  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 All rights reserved.  |  Contact the author