var List: TStrings;
procedure BuildList(Path: string; Refresh: Boolean = True);
var Handle: Cardinal; Index: Integer; FindData: TWin32FindData;
begin
if Refresh then List.Clear;
Handle := FindFirstFile(PChar(Path + '\*.*'), FindData);
if Handle <> INVALID_HANDLE_VALUE then
begin
repeat
with FindData do
if ((dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) and
(string(cFileName) <> '.') and (cFileName <> '..') then
if Refresh then
List.Add(cFileName)
else
begin
Index := List.IndexOf(cFileName);
if Index <> -1 then
List.Delete(Index)
else
List.Add(cFileName);
end;
until not FindNextFile(Handle, FindData);
Windows.FindClose(Handle);
end;
end;
function Thread(Handle: Cardinal): Cardinal; stdcall;
label Next; var Path: string;
begin
List := TStringList.Create;
Path := Form1.ShellListView.Root;
if Path[Length(Path)] = '\' then
SetLength(Path, Length(Path) - 1);
BuildList(Path);
Handle := FindFirstChangeNotification(PChar(Path), False, FILE_NOTIFY_CHANGE_DIR_NAME);
Next: WaitForSingleObject(Handle, INFINITE);
BuildList(Path, False);
Form1.ListBox.Items := List; FindNextChangeNotification(Handle);
BuildList(Path);
goto Next;
end;
procedure TForm1.FormCreate(Sender: TObject);
var Dummy: Cardinal;
begin
CreateThread(nil, 0, @Thread, nil, 0, Dummy);
Caption := 'Change to see: ' + ShellListView.Root;
end;