That is the case, one recycle bin per partition. The reason for it is, when the file is "deleted" it is simply moved to the recycle bin folder instead of copied to it (which is much faster and makes the time spent "deleting" independent of the file size.)
Yes, it physically one recycle bin per partition. But I think if you use the object Shell.Application THEN the recycle bin will contain (
show) the deleted files from ALL the partitions (just like when you open the recycle bin on your desktop, see for yourself by opening the recycle bin on your desktop).
In powershell it's easy. It's a oneliner
$sum=0;
(New-Object -com shell.application
).Namespace
(10).items
() | Foreach {$sum+=$_.Size
}; $sum
I tried in Lazarus but somehow I couldn't get NameSpace(10) to work correctly.
For the C:\Temp it works.
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
ObjShell, ObjFolder: olevariant;
I: integer;
begin
ObjShell := CreateOleObject('Shell.Application');
ObjFolder := ObjShell.NameSpace(10); // 10 = RECYCLE_BIN ???????
ObjFolder := ObjShell.NameSpace('C:\Temp'); // DESKTOP
if ObjFolder <> Null then
begin
Memo1.Lines.Add('Folder: ' + ObjFolder.Title);
for I := 0 to ObjFolder.Items.Count - 1 do
Memo1.Lines.Add(ObjFolder.Items.Item(I).Name + ' ' + IntToStr(ObjFolder.Items.Item(I).Size));
end;
end;
Now why doesn't it work for NameSpace(10) (which should work for the recycle bin).
Edit: Ok, I got it working. You really need to pass HEX $A as Variant.
This works now:
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
ObjShell, ObjFolder: olevariant;
I, Size: integer;
begin
ObjShell := CreateOleObject('Shell.Application');
ObjFolder := ObjShell.NameSpace(OleVariant($A)); // 10 = RECYCLE_BIN
if ObjFolder <> Null then
begin
Memo1.Lines.Add('Folder: ' + ObjFolder.Title);
Size := 0;
for I := 0 to ObjFolder.Items.Count - 1 do
Size := Size + ObjFolder.Items.Item(I).Size;
Memo1.Lines.Add('Total size = ' + Size.ToString);
end;
end;
Can you work with this?
(I found that it's not really lightning fast. I would expected it to iterate through the bin faster.)