Description |
The GetFiles method returns an array of FileInfo objects for all 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
System.IO.DirectoryInfo.GetFiles
|
|
|
|
An example of the 1st syntax |
program Project1;
{$APPTYPE CONSOLE}
uses
System.IO;
var
DirInfo : System.IO.DirectoryInfo;
Path : String;
Files : Array of FileInfo;
i : Integer;
begin // Get the current folder
Path := System.IO.Directory.GetCurrentDirectory;
Console.WriteLine('Files in : ' + Path + ' :');
Console.WriteLine;
// Create our directory info object
DirInfo := System.IO.DirectoryInfo.Create(Path);
// Get the files in this folder
Files := DirInfo.GetFiles;
// 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.
|
Files in : C:\Documents and Settings\Thomas\My Documents\Borland Studio Projects :
DelphiBasics.txt
Project1.exe
Project1.pdb
Project1.rsp
|
|
An example of the 2nd syntax |
program Project1;
{$APPTYPE CONSOLE}
uses
System.IO;
var
DirInfo : System.IO.DirectoryInfo;
Path : String;
Files : Array of FileInfo;
i : Integer;
begin // Get the current folder
Path := System.IO.Directory.GetCurrentDirectory;
Console.WriteLine('Project Files in : ' + Path + ' :');
Console.WriteLine;
// Create our directory info object
DirInfo := System.IO.DirectoryInfo.Create(Path);
// Get the project files in this folder
Files := DirInfo.GetFiles('Project*');
// 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.
|
Project Files in : C:\Documents and Settings\Thomas\My Documents\Borland Studio Projects :
Project1.exe
Project1.pdb
Project1.rsp
|
|