{$IF CompilerVersion >= 23}
{$DEFINE NameSpace}
{$ELSE CompilerVersion}
{$UNDEF NameSpace}
{$IFEND CompilerVersion}
unit Unit4;
interface
uses
{$IFDEF NameSpace}
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
{$ELSE NameSpace}
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
{$ENDIF NameSpace}
const
kernelbase = '
kernel32.dll';
FIND_FIRST_EX_LARGE_FETCH = 2;
MAX_PATH = 260;
type
LPWSTR = PWideChar;
_WIN32_FIND_DATAW =
record
dwFileAttributes: DWORD;
ftCreationTime: TFileTime;
ftLastAccessTime: TFileTime;
ftLastWriteTime: TFileTime;
nFileSizeHigh: DWORD;
nFileSizeLow: DWORD;
dwReserved0: DWORD;
dwReserved1: DWORD;
cFileName:
array[0..MAX_PATH - 1]
of WideChar;
cAlternateFileName:
array[0..13]
of WideChar;
end;
WIN32_FIND_DATAW = _WIN32_FIND_DATAW;
TWin32FindDataW = _WIN32_FIND_DATAW;
_FINDEX_INFO_LEVELS = (FindExInfoStandard, FindExInfoBasic, FindExInfoMaxInfoLevel);
TFindexInfoLevels = _FINDEX_INFO_LEVELS;
_FINDEX_SEARCH_OPS = (FindExSearchNameMatch, FindExSearchLimitToDirectories,
FindExSearchLimitToDevices);
TFindexSearchOps = _FINDEX_SEARCH_OPS;
function FindFirstFileExW(lpFileName: LPWSTR; fInfoLevelId: TFindexInfoLevels;
lpFindFileData: Pointer; fSearchOp: TFindexSearchOps; lpSearchFilter: Pointer;
dwAdditionalFlags: DWORD): THandle;
stdcall;
function FindNextFileW(hFindFile: THandle;
var lpFindFileData: TWIN32FindDataW): BOOL;
stdcall;
type
TForm4 =
class(TForm)
edPath: TEdit;
edMask: TEdit;
lbFiles: TListBox;
btnStart: TButton;
procedure btnStartClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
function FindFirstFileExW;
external kernelbase
name '
FindFirstFileExW';
function FindNextFileW;
external kernelbase
name '
FindNextFileW';
procedure TForm4.btnStartClick(Sender: TObject);
var
SL: TStringList;
hFile: THandle;
FindDataW: TWIN32FindDataW;
begin
SL := TStringList.Create;
try
hFile := FindFirstFileExW(PWideChar(edPath.Text + edMask.Text), FindExInfoBasic, @FindDataW, FindExSearchNameMatch,
nil, FIND_FIRST_EX_LARGE_FETCH);
if hFile <> INVALID_HANDLE_VALUE
then
begin
repeat
if (((FindDataW.dwFileAttributes
and FILE_ATTRIBUTE_DIRECTORY) = 0)
and (FindDataW.cFileName <> WideString('
.'))
and (FindDataW.cFileName <> WideString('
..')))
then
begin
SL.Add(WideString(FindDataW.cFileName));
end;
until (
not FindNextFileW(hFile, FindDataW));
end;
{$IFDEF NameSpace}Winapi.
{$ENDIF NameSpace}Windows.FindClose(hFile);
lbFiles.Items.BeginUpdate;
lbFiles.Clear;
lbFiles.Items := SL;
lbFiles.Items.EndUpdate;
finally
SL.Free;
end;
end;
end.