Come ricavare il numero di elementi nel cestino e la loro dimensione
Scritto da
Massimo Bonanni il
lunedì 18 luglio 2011
•
Linguaggio:
• Livello: 100
Per poter ricavare il numero di elementi
nel cestino di windows e la loro
dimensione possiamo ricorrere alla tecnica del P/Invoke ed
utilizzare l'API SHQueryRecycleBin contenuta nella
shell32.dll.
La seguente classe implementa un metodo per recuperare numero di
elementi e dimensione (in bytes) degli stessi:
VB.NET
Imports System.Runtime.InteropServices
Public Class RecycleBinHelper
Private Const S_OK = 0
<DllImport("shell32.dll")>
Private Shared Function SHQueryRecycleBin(ByVal pszRootPath As String, ByRef pSHQueryRBInfo As SHQUERYRBINFO) As Integer
End Function
Public Shared Function GetSize(ByRef numItems As Integer, ByRef totalSize As Int64) As Boolean
Dim retval = False
Dim shrb = New SHQUERYRBINFO()
shrb.cbSize = Marshal.SizeOf(GetType(SHQUERYRBINFO))
If SHQueryRecycleBin(String.Empty, shrb) = S_OK Then
totalSize = shrb.i64Size
numItems = CInt(shrb.i64NumItems)
retval = True
End If
Return retval
End Function
<StructLayout(LayoutKind.Sequential, Pack:=4)>
Private Structure SHQUERYRBINFO
Public cbSize As Int32
Public i64Size As Long
Public i64NumItems As Long
End Structure
End Class
Tags: PInvoke