![]() Example |
![]() ![]() ![]() |
dcMultiDiskScanner and dcDiskScanner components.
|
type
|
TdcFileFoundEvent = procedure(Sender: TObject;
|
FileName, FileType: String; FileSize: Extended;
|
FileTime: TDateTime; FileAttributes: TdcScanAttributes;
|
LargeIcon, SmallIcon: TIcon; SysImageIndex: Integer;
|
TotalFiles: Integer; TotalSize: Extended) of object;
|
|
property OnFileFound: TdcFileFoundEvent;
|
The OnFileFound event occurs when the dcMultiDiskScanner component found the file or directory (if saDirectory specified in the SearchAttributes) that matches to specified criteria (IncludeList / ExcludeList lists, SearchAttributes, SearchSize and SearchTime properties).
|
|
Use the OnFileFound event handler to take specific action once the DiskScanner found files, and, for example, add this file to the list with search results. Please check out an example of handling this event.
|
FileName | The name of found file with full path to this file. Use ExtractFileName and ExtractFilePath routines from SysUtils unit to split the file name and path.
|
FileType | The type of file extension, if it was registered in the shell. If extension was not registered, return value will be "EXT file", where EXT is the file extension.
|
FileSize | Size of found file in bytes. Use FloatToStr function to convert this value to string
|
FileTime | Time of last modification;
|
FileAttributes | The set of file attributes (Normal, Archive, ReadOnly, Hidden, System or Directory). See TdcScanAttributes type.
|
LargeIcon,
|
SmallIcon | 32x32 and 16x16 icons, associated with this file extension in the shell. If file has .EXE extension, icon will be extracted from executable file. If file is Icon, the Icon image will returned. ![]() |
SysImageIndex | determines an icon index in the system ImageList. Use this parameter only if you're using dcSystemImageList component as source of images for the ListView. ![]() |
TotalFiles | Total number of found files per current search session.
|
TotalSize | Total size of all files that found in current search session. Use FloatToStr function to convert this value to string.
|
![]() |
Following example demonstrates how to handle the OnFileFound event of dcDiskScanner or dcMultiDiskScanner component. Let's say, we have the ResultsListView: TListView which we would like to fill with the search results and ImageList: TImageList which contains the 16x16 images associated with the file types.
|
|
procedure TForm1.dcDiskScannerFileFound(Sender: TObject; FileName,
|
FileType: String; FileSize: Extended; FileTime: TDateTime;
|
FileAttributes: TdcScanAttributes;
|
LargeIcon, SmallIcon: TIcon; SysImageIndex: Integer;
|
TotalFiles: Integer; TotalSize: Extended);
|
const
|
KBStr = 'KB';
|
var
|
St: String;
|
ListItem: TListItem;
|
begin
|
StatusBar.Panels[1].Text := 'Files ' + IntToStr(TotalFiles);
|
StatusBar.Panels[2].Text := 'Total size: ' + FloatToStr(TotalSize) + ' bytes';
|
|
ListItem := ListView1.Items.Add; // adding new item
|
{** file name}
|
ListItem.Caption := FileName;
|
{** file type}
|
ListItem.SubItems.Add(FileType);
|
{** file size}
|
if not (saDirectory in FileAttributes) then
|
if FileSize <> 0 then
|
St := FloatToStrF(Int(FileSize / 1024 + 1), ffNumber, 18, 0) + KBStr
|
else
|
St := '0' + KBStr
|
else
|
St := '';
|
ListItem.SubItems.Add(St);
|
{** file time}
|
ListItem.SubItems.Add(DateTimeToStr(FileTime));
|
|
{** icon image }
|
ListItem.ImageIndex := SysImageIndex;
|
if saHidden in FileAttributes then
|
ListItem.Cut := True; { ghosted icon for hidden files }
|
St := LowerCase(ExtractFileExt(FileName));
|
{ adding shortcut overlay for .lnk and .url }
|
if (St = '.lnk') or (St = '.url') then
|
ListItem.OverlayIndex := 1;
|
|
{ //* Use code below if you don't want to use
|
//* system images and set DiskScanner1.UseIcons to True
|
ListItem.ImageIndex := ImageList1.Count;
|
ImageList1.AddIcon(SmallIcon); }
|
end;
|
OnScanFolder, OnScanDone events;
|
Execute, Stop methods.
|