Rubrik: System/Windows | VB-Versionen: VB2005, VB2008 | 16.10.09 |
Anzahl Dateien und Größe im Windows Papierkorb ermitteln Dieser Tipp zeigt, wie sich die Anzahl Dateien und deren Gesamtgröße im Windows-Papierkorb ermitteln lassen - entweder systemweit oder optional auch nur für ein bestimmtes Laufwerk. | ||
Autor: Dieter Otter | Bewertung: | Views: 10.405 |
www.tools4vb.de | System: Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Dieser Tipp zeigt, wie sich die Anzahl Dateien und deren Gesamtgröße im Windows-Papierkorb ermitteln lassen - entweder systemweit oder optional auch nur für ein bestimmtes Laufwerk.
Imports System.Runtime.InteropServices
' API-Deklarationen <DllImport("shell32.dll")> _ Private Shared Function SHQueryRecycleBin( _ ByVal pszRootPath As String, _ ByRef ptSHQueryRBInfo As SHQUERYRBINFO) As Int32 End Function <StructLayout(LayoutKind.Sequential, Pack:=1)> _ Private Structure SHQUERYRBINFO Dim cbSize As Int32 Dim i64Size As Long Dim i64NumItems As Long End Structure Public Structure RBINFO Dim NumItems As Long Dim TotalSize As Long End Structure
''' <summary> ''' Ermittelt die Anzahl Dateien und deren Größe im Windows-Papierkorb ''' </summary> ''' <param name="sPath">Optional. Laufwerk, für das die Informationen ermittlet werden sollen.</param> Public Function RecycleBinInfo(Optional ByVal sPath As String = "") As RBINFO Dim RB As SHQUERYRBINFO = New SHQUERYRBINFO ' API-Funktion aufrufen RB.cbSize = Marshal.SizeOf(GetType(SHQUERYRBINFO)) Call SHQueryRecycleBin(sPath, RB) ' Rückgabewerte With RecycleBinInfo .NumItems = RB.i64NumItems .TotalSize = RB.i64Size End With End Function
Aufrufbeispiel:
' Anzahl Dateien im Windows Papierkorb ermitteln With RecycleBinInfo() ListBox1.Items.Add("Anzahl Dateien: " & .NumItems) ListBox1.Items.Add("Gesamtgröße (Bytes): " & .TotalSize) ListBox1.Items.Add("") End With
' Anzahl Dateien im Windows Papierkorb auf Laufwerk C: With RecycleBinInfo("C:") ListBox1.Items.Add("Anzahl Dateien: " & .NumItems) ListBox1.Items.Add("Gesamtgröße (Bytes): " & .TotalSize) ListBox1.Items.Add("") End With