Hi,
How I can create one list of the files opened on one directory/drive?
Thanks
List files opened
I try this but the procedure is very slow.
Code: Select all
procedure TForm3.Button1Click(Sender: TObject);
var i1, i2: Integer;
begin
memo1.Clear;
with Processes do
for i1 := 0 to ItemCount - 1 do
for i2 := 0 to Items[i1].Handles.ItemCount - 1 do
begin
Application.ProcessMessages;
if not Items[i1].Handles.Items[i2].IsValid then Continue;
if not (Items[i1].Handles.Items[i2].ObjType in [otFile, otFileMapping]) then Continue;
if Items[i1].Handles.Items[i2].KernelObj.ObjName = '' then Continue;
memo1.Lines.Add (Items[i1].Handles.Items[i2].KernelObj.ObjName);
end;
end;
You can speed that up a bit by using "with" as often as possible. Methods like "IProcess.Handles" may otherwise redo the enumeration everytime you call it.
See what I mean?
Code: Select all
procedure TForm3.Button1Click(Sender: TObject);
var i1, i2: Integer;
strVar: string;
begin
memo1.Clear;
with Processes do
for i1 := 0 to ItemCount - 1 do
with Items[i1].Handles do
for i2 := 0 to ItemCount - 1 do
with Items[i2] do
begin
Application.ProcessMessages;
if not IsValid then Continue;
if not (ObjType in [otFile, otFileMapping]) then Continue;
strVar := KernelObj.ObjName;
if strVar = '' then Continue;
memo1.Lines.Add (strVar);
end;
end;