type
//
// Declarations for the infos about the recycle bin
//
PSHQueryRBInfo = ^TSHQueryRBInfo;
TSHQueryRBInfo =
packed record
cbSize: DWORD;
i64Size: Int64;
i64NumItems: Int64;
end;
function SHQueryRecycleBin(szRootPath: PAnsiChar; SHQueryRBInfo: PSHQueryRBInfo): HResult;
stdcall;
external '
shell32.dll'
Name '
SHQueryRecycleBinA';
{...}
function GetDllVersion(FileName:
string): Integer;
var
InfoSize, Wnd: DWORD;
VerBuf: Pointer;
FI: PVSFixedFileInfo;
VerSize: DWORD;
begin
Result := 0;
InfoSize := GetFileVersionInfoSize(PChar(FileName), Wnd);
if InfoSize <> 0
then
begin
GetMem(VerBuf, InfoSize);
try
if GetFileVersionInfo(PChar(FileName), Wnd, InfoSize, VerBuf)
then
if VerQueryValue(VerBuf, '
\', Pointer(FI), VerSize)
then
Result := FI.dwFileVersionMS;
finally
FreeMem(VerBuf);
end;
end;
end;
procedure RecycleBinInfo(
const Drive: PAnsiChar;
out BinSize, FileCount: Int64);
var
DllVersion : integer;
SHQueryRBInfo : TSHQueryRBInfo;
r : HResult;
begin
DllVersion := GetDllVersion(PChar('
shell32.dll'));
if DllVersion >= $00040048
then
begin
FillChar(SHQueryRBInfo, SizeOf(TSHQueryRBInfo), #0);
SHQueryRBInfo.cbSize := SizeOf(TSHQueryRBInfo);
R := SHQueryRecycleBin(Drive, @SHQueryRBInfo);
if r = s_OK
then
begin
BinSize := SHQueryRBInfo.i64Size;
FileCount := SHQueryRBInfo.i64NumItems;
end
else
RaiseLastOSError();
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
CountFiles, BinSize: Int64;
begin
try
RecycleBinInfo('
c:', BinSize, CountFiles);
ShowMessage(IntToStr(CountFiles));
except
on E:
Exception do
ShowMessage(E.
Message);
end;
end;