How to check if the recycle bin is empty in DElphi.
Posted on 2013-02-05
I am using Delphi 2010 on a Win 7 64 bit machine and I need to check if the recycle bin is empty. I picked up the following from the web
function RecycleBinIsEmpty: Boolean;
CLSID_IRecycleBin: TGUID = (D1: $645FF040; D2: $5081; D3: $101B;
D4: ($9F, $08, $00, $AA, $00, $2F, $95, $4E));
OleCheck(CoCreateInstance(CLSID_IRecycleBin, nil, CLSCTX_INPROC_SERVER or
CLSCTX_LOCAL_SERVER, IID_IShellFolder, RecycleBin));
Result := EnumIDList.Next(1, FileItemIDList, ItemCount) <> NOERROR;
but no matter what the result always indicates the Recycle Bin is empty even when I have checked that it is not empty. I even tried checking the number of items in the recycle bin using
rbinfo.cbSize := SizeOf(rbinfo);
Retval := SHQueryRecycleBin('',@rbinfo);
But Retval always ends up as 0.
Has anyone got any idea what is going wrong?