THYDirectory
Overview
The THYDirectory class provides a convenient and object oriented way to access disk directories.
Although it can be used independently, THYDirectory is usually returned by either the THYDirectoryManager component or a THYDirectory parent.
The Refresh method provides an intuitive way to search for child files or directories which will be accessible through the use of the Files and Directories array properties.
Use Case
You can use the THYDirectory class to access disk directories and files.
For example:
procedure ListPlugins(const Dir: string; List: TStrings);
var
HyDir: THYDirectory;
I: Integer;
begin
HyDir := THYDirectory.Create(nil, Dir);
try
HyDir.Refresh('*.dll', [roFiles]);
for I := 0 to HyDir.FileCount - 1 do
List.Add(HyDir.Files[i].Name);
finally
HyDir.Free;
end;
end;
Location
- Unit: Hydra.RO.FileUtils.pas
- Ancestry: TInterfacedObject | THYCustomFile | THYDirectory
constructor Create (THYDirectory, TSearchRec) override
Creates a new instance of the class.
constructor Create(aParent: THYDirectory; aSearchRec: TSearchRec)
Parameters:
- aParent: Reference to a parent directory.
- aSearchRec: Pointer to a TSearchRec structure.
constructor Create (THYDirectory, string) overload (declared in THYCustomFile)
Creates a new instance of the class.
constructor Create(aParent: THYDirectory; const aName: string)
Parameters:
- aParent: Reference to a parent directory.
- aName: Name of the item.
AssignAttributes protected
Copies event handlers and options from the specifies source.
procedure AssignAttributes(const Source: IHYDirectoryAttributes)
Parameters:
- Source: Reference to a source instance.
Attributes (declared in THYCustomFile)
Gets or sets file attributes. Attributes values is a standard delphi values for TSearchRec.
property Attributes: Integer read write
AttributesString (declared in THYCustomFile)
Gets string representation of the file attributes.
property AttributesString: string read
Clear
Clears files and sub-directories list.
procedure Clear
ClearSavedDirectoriesList
Clears list of a saved directories.
procedure ClearSavedDirectoriesList
CopyBufferSize
Gets or sets value that indicates size of the buffer that will be used when copying files.
property CopyBufferSize: Integer read write
CopyFile
Copies file with specified name into a specified directory.
procedure CopyFile(const aFileName: string; const aDestinationDirectory: string)
Parameters:
- aFileName: Path to a file.
- aDestinationDirectory: Path to a destination directory.
CopyFiles
Copies list of files into a specified directory.
procedure CopyFiles(const aDestinationDirectory: string; const aList: array of string)
Parameters:
- aDestinationDirectory: Path to a destination directory.
- aList: Array of file names.
CreateDirectoryObject protected dynamic
Creates a new instance of the class with specified parameters.
function CreateDirectoryObject(aParent: THYDirectory; aSearchRec: TSearchRec): THYDirectory
Parameters:
- aParent: Reference to a parent directory.
- aSearchRec: Pointer to a TSearchRec structure.
CreateFileObject protected dynamic
Creates new instance of a THYFile object with specified parameters.
function CreateFileObject(aParent: THYDirectory; aSearchRec: TSearchRec): THYFile
Parameters:
- aParent: Reference to a parent directory.
- aSearchRec: Pointer to a TSearchRec structure.
Data (declared in THYCustomFile)
Gets or sets pointer to a custom data associated with the file.
property Data: pointer read write
Directories
Gets reference to a sub-directory with specified index.
property Directories[Index: Integer]: THYDirectory read
Directory (declared in THYCustomFile)
Gets reference to a parent directory.
property Directory: THYDirectory read
DirectoryCount
Gets number of a sub-directories.
property DirectoryCount: Integer read
FileCount
Gets number of files.
property FileCount: Integer read
FileMask
Gets mask of a file search.
property FileMask: string read
Files
Gets reference to a file with specified index.
property Files[Index: Integer]: THYFile read
FullName (declared in THYCustomFile)
Gets full path of the file.
property FullName: string read
GetCopyBufferSize protected
function GetCopyBufferSize: Integer
GetFullName protected virtual (declared in THYCustomFile)
Returns full path of the file.
function GetFullName: string
GetOnCopyFileEnd protected
function GetOnCopyFileEnd: THYFileCopyEndEvent
GetOnCopyFileProgress protected
function GetOnCopyFileProgress: THYFileCopyProgressEvent
GetOnCopyFileStart protected
function GetOnCopyFileStart: THYFileCopyStartEvent
GetOnFindDirectory protected
function GetOnFindDirectory: THYFindDirectoryEvent
GetOnFindFile protected
function GetOnFindFile: THYFindFileEvent
GetOptions protected
function GetOptions: THYDirectoryOptions
GetSize protected override
function GetSize: Integer
Name (declared in THYCustomFile)
Gets or sets name of the file.
property Name: string read write
OnCopyFileEnd
Gets or sets event handler that is triggered after file was copied.
property OnCopyFileEnd: THYFileCopyEndEvent read write
delegate: procedure OnCopyFileEnd(Sender: THYDirectory; Source: THYFile; Destination: THYFile)
OnCopyFileProgress
Gets or sets event handler that is triggered on file copy.
property OnCopyFileProgress: THYFileCopyProgressEvent read write
delegate: procedure OnCopyFileProgress(Sender: THYDirectory; Source: THYFile; const Destination: string; Position: Integer; TotalSize: Integer)
OnCopyFileStart
Gets or sets event handler that is triggered before file is copied.
property OnCopyFileStart: THYFileCopyStartEvent read write
delegate: procedure OnCopyFileStart(Sender: THYDirectory; Source: THYFile; const Destination: string)
OnFindDirectory
Gets or sets event handler that is triggered on directory search.
property OnFindDirectory: THYFindDirectoryEvent read write
delegate: procedure OnFindDirectory(Sender: THYDirectory; aDirectory: THYDirectory; var Accept: Boolean)
OnFindFile
Gets or sets event handler that is triggered on file search.
property OnFindFile: THYFindFileEvent read write
delegate: procedure OnFindFile(Sender: THYDirectory; aFile: THYFile; var Accept: Boolean)
Options
Gets or sets directory options.
property Options: THYDirectoryOptions read write
PopDir
Restores directory from a saved list.
function PopDir: Boolean
PushDir
Places current directory into the saved directories list.
procedure PushDir
Refresh
Refreshes files and folders list with specified parameters.
function Refresh(const aFileMask: string; Options: THYDirectoryRefreshOptions; Recursive: Boolean; aSearchAttr: Integer): Integer
Parameters:
- aFileMask: Mask for the file search.
- Options: Refresh parameters.
- Recursive: Value that indicates whether recursive search will be performed or in the current directory only.
- aSearchAttr: File parameters.
RefreshedDirectories
Gets a value that indicates whether directories was refreshed.
property RefreshedDirectories: Boolean read
RefreshedFiles
Gets a value that indicates whether files was refreshed.
property RefreshedFiles: Boolean read
SavedDirectories
Gets saved directory with specified index.
property SavedDirectories[Index: Integer]: string read
SavedDirectoryCount
Gets number of the saved directories.
property SavedDirectoryCount: Integer read
SetCopyBufferSize protected
procedure SetCopyBufferSize(const Value: Integer)
Parameters:
- Value:
SetOnCopyFileEnd protected
procedure SetOnCopyFileEnd(const Value: THYFileCopyEndEvent)
Parameters:
- Value:
SetOnCopyFileProgress protected
procedure SetOnCopyFileProgress(const Value: THYFileCopyProgressEvent)
Parameters:
- Value:
SetOnFileCopyStart protected
procedure SetOnFileCopyStart(const Value: THYFileCopyStartEvent)
Parameters:
- Value:
SetOnFindDirectory protected
procedure SetOnFindDirectory(const Value: THYFindDirectoryEvent)
Parameters:
- Value:
SetOnFindFile protected
procedure SetOnFindFile(const Value: THYFindFileEvent)
Parameters:
- Value:
SetOptions protected
procedure SetOptions(const Value: THYDirectoryOptions)
Parameters:
- Value:
Size (declared in THYCustomFile)
Gets size of the file.
property Size: Integer read
Time (declared in THYCustomFile)
Gets or sets file time.
property Time: TDateTime read write
Version (declared in THYCustomFile)
Gets string representation of the file version.
property Version: string read
Attributes (declared in THYCustomFile)
Gets or sets file attributes. Attributes values is a standard delphi values for TSearchRec.
property Attributes: Integer read write
AttributesString (declared in THYCustomFile)
Gets string representation of the file attributes.
property AttributesString: string read
CopyBufferSize
Gets or sets value that indicates size of the buffer that will be used when copying files.
property CopyBufferSize: Integer read write
Data (declared in THYCustomFile)
Gets or sets pointer to a custom data associated with the file.
property Data: pointer read write
Directories
Gets reference to a sub-directory with specified index.
property Directories[Index: Integer]: THYDirectory read
Directory (declared in THYCustomFile)
Gets reference to a parent directory.
property Directory: THYDirectory read
DirectoryCount
Gets number of a sub-directories.
property DirectoryCount: Integer read
FileCount
Gets number of files.
property FileCount: Integer read
FileMask
Gets mask of a file search.
property FileMask: string read
Files
Gets reference to a file with specified index.
property Files[Index: Integer]: THYFile read
FullName (declared in THYCustomFile)
Gets full path of the file.
property FullName: string read
Name (declared in THYCustomFile)
Gets or sets name of the file.
property Name: string read write
Options
Gets or sets directory options.
property Options: THYDirectoryOptions read write
RefreshedDirectories
Gets a value that indicates whether directories was refreshed.
property RefreshedDirectories: Boolean read
RefreshedFiles
Gets a value that indicates whether files was refreshed.
property RefreshedFiles: Boolean read
SavedDirectories
Gets saved directory with specified index.
property SavedDirectories[Index: Integer]: string read
SavedDirectoryCount
Gets number of the saved directories.
property SavedDirectoryCount: Integer read
Size (declared in THYCustomFile)
Gets size of the file.
property Size: Integer read
Time (declared in THYCustomFile)
Gets or sets file time.
property Time: TDateTime read write
Version (declared in THYCustomFile)
Gets string representation of the file version.
property Version: string read
constructor Create (THYDirectory, TSearchRec) override
Creates a new instance of the class.
constructor Create(aParent: THYDirectory; aSearchRec: TSearchRec)
Parameters:
- aParent: Reference to a parent directory.
- aSearchRec: Pointer to a TSearchRec structure.
constructor Create (THYDirectory, string) overload (declared in THYCustomFile)
Creates a new instance of the class.
constructor Create(aParent: THYDirectory; const aName: string)
Parameters:
- aParent: Reference to a parent directory.
- aName: Name of the item.
AssignAttributes protected
Copies event handlers and options from the specifies source.
procedure AssignAttributes(const Source: IHYDirectoryAttributes)
Parameters:
- Source: Reference to a source instance.
Clear
Clears files and sub-directories list.
procedure Clear
ClearSavedDirectoriesList
Clears list of a saved directories.
procedure ClearSavedDirectoriesList
CopyFile
Copies file with specified name into a specified directory.
procedure CopyFile(const aFileName: string; const aDestinationDirectory: string)
Parameters:
- aFileName: Path to a file.
- aDestinationDirectory: Path to a destination directory.
CopyFiles
Copies list of files into a specified directory.
procedure CopyFiles(const aDestinationDirectory: string; const aList: array of string)
Parameters:
- aDestinationDirectory: Path to a destination directory.
- aList: Array of file names.
CreateDirectoryObject protected dynamic
Creates a new instance of the class with specified parameters.
function CreateDirectoryObject(aParent: THYDirectory; aSearchRec: TSearchRec): THYDirectory
Parameters:
- aParent: Reference to a parent directory.
- aSearchRec: Pointer to a TSearchRec structure.
CreateFileObject protected dynamic
Creates new instance of a THYFile object with specified parameters.
function CreateFileObject(aParent: THYDirectory; aSearchRec: TSearchRec): THYFile
Parameters:
- aParent: Reference to a parent directory.
- aSearchRec: Pointer to a TSearchRec structure.
GetCopyBufferSize protected
function GetCopyBufferSize: Integer
GetFullName protected virtual (declared in THYCustomFile)
Returns full path of the file.
function GetFullName: string
GetOnCopyFileEnd protected
function GetOnCopyFileEnd: THYFileCopyEndEvent
GetOnCopyFileProgress protected
function GetOnCopyFileProgress: THYFileCopyProgressEvent
GetOnCopyFileStart protected
function GetOnCopyFileStart: THYFileCopyStartEvent
GetOnFindDirectory protected
function GetOnFindDirectory: THYFindDirectoryEvent
GetOnFindFile protected
function GetOnFindFile: THYFindFileEvent
GetOptions protected
function GetOptions: THYDirectoryOptions
GetSize protected override
function GetSize: Integer
PopDir
Restores directory from a saved list.
function PopDir: Boolean
PushDir
Places current directory into the saved directories list.
procedure PushDir
Refresh
Refreshes files and folders list with specified parameters.
function Refresh(const aFileMask: string; Options: THYDirectoryRefreshOptions; Recursive: Boolean; aSearchAttr: Integer): Integer
Parameters:
- aFileMask: Mask for the file search.
- Options: Refresh parameters.
- Recursive: Value that indicates whether recursive search will be performed or in the current directory only.
- aSearchAttr: File parameters.
SetCopyBufferSize protected
procedure SetCopyBufferSize(const Value: Integer)
Parameters:
- Value:
SetOnCopyFileEnd protected
procedure SetOnCopyFileEnd(const Value: THYFileCopyEndEvent)
Parameters:
- Value:
SetOnCopyFileProgress protected
procedure SetOnCopyFileProgress(const Value: THYFileCopyProgressEvent)
Parameters:
- Value:
SetOnFileCopyStart protected
procedure SetOnFileCopyStart(const Value: THYFileCopyStartEvent)
Parameters:
- Value:
SetOnFindDirectory protected
procedure SetOnFindDirectory(const Value: THYFindDirectoryEvent)
Parameters:
- Value:
SetOnFindFile protected
procedure SetOnFindFile(const Value: THYFindFileEvent)
Parameters:
- Value:
SetOptions protected
procedure SetOptions(const Value: THYDirectoryOptions)
Parameters:
- Value:
OnCopyFileEnd
Gets or sets event handler that is triggered after file was copied.
property OnCopyFileEnd: THYFileCopyEndEvent read write
delegate: procedure OnCopyFileEnd(Sender: THYDirectory; Source: THYFile; Destination: THYFile)
OnCopyFileProgress
Gets or sets event handler that is triggered on file copy.
property OnCopyFileProgress: THYFileCopyProgressEvent read write
delegate: procedure OnCopyFileProgress(Sender: THYDirectory; Source: THYFile; const Destination: string; Position: Integer; TotalSize: Integer)
OnCopyFileStart
Gets or sets event handler that is triggered before file is copied.
property OnCopyFileStart: THYFileCopyStartEvent read write
delegate: procedure OnCopyFileStart(Sender: THYDirectory; Source: THYFile; const Destination: string)
OnFindDirectory
Gets or sets event handler that is triggered on directory search.
property OnFindDirectory: THYFindDirectoryEvent read write
delegate: procedure OnFindDirectory(Sender: THYDirectory; aDirectory: THYDirectory; var Accept: Boolean)
OnFindFile
Gets or sets event handler that is triggered on file search.
property OnFindFile: THYFindFileEvent read write
delegate: procedure OnFindFile(Sender: THYDirectory; aFile: THYFile; var Accept: Boolean)