Rubrik: System/Windows | VB-Versionen: VB2022 | 07.07.25 |
![]() Diese spezielle Programmierung kann von praktischem Nutzen sein. | ||
Autor: ![]() | Bewertung: ![]() ![]() ![]() ![]() ![]() | Views: 391 |
ohne Homepage | System: Win7, Win8, Win10, Win11 | kein Beispielprojekt |
Der Tipp zeigt, wie man mit wenig Programm die angegebene Aufgabe lösen kann.
Zunächst die Hintergrund-Programmierung:
Imports System.Runtime.InteropServices Module dhmodPapierkorb <StructLayout(LayoutKind.Sequential, Pack:=1)> Public Structure SHQUERYRBINFO Dim cbSize As Int64 Dim i64Size As Long Dim i64NumItems As Long End Structure <DllImport("shell32.dll")> Public Function SHQueryRecycleBin(pszRootPath As String, ByRef ptSHQueryRBInfo As SHQUERYRBINFO) As Int64 End Function End Module
Hier die Anwendungsprogrammierung:
' Anzahl und Größe Dateien im Windows Papierkorb ' ermitteln, AnyCPU Dim info As SHQUERYRBINFO With info .cbSize = Len(info) SHQueryRecycleBin(Nothing, info) lblAnzD.Text = .i64NumItems.ToString lblSizeD.Text = FormatBytesSys(.i64Size) End With
Und als Zugabe eine Hilfsfunktion:
' file's size, art via suffix (in B, KB, MB, GB) Public Function FormatBytesSys(BytesCaller As ULong, Optional suffixArt As String = "k") As String 'art... k (Kurzbezeichnung der Größe) 'art... nicht k (Langbezeichnung) Dim DoubleBytes As Double Try Select Case BytesCaller Case Is >= 1099511627776 DoubleBytes = CDbl(BytesCaller / 1099511627776) 'TB Return FormatNumber(DoubleBytes, 2) & If(suffixArt = "k", " TB", " Terabyte") Case 1073741824 To 1099511627775 DoubleBytes = CDbl(BytesCaller / 1073741824) 'GB Return FormatNumber(DoubleBytes, 2) & If(suffixArt = "k", " GB", " Gigabyte") Case 1048576 To 1073741823 DoubleBytes = CDbl(BytesCaller / 1048576) 'MB Return FormatNumber(DoubleBytes, 2) & If(suffixArt = "k", " MB", " Megabyte") Case 1024 To 1048575 DoubleBytes = CDbl(BytesCaller / 1024) 'KB Return FormatNumber(DoubleBytes, 2) & If(suffixArt = "k", " KB", " Kilobyte") Case 0 To 1023 DoubleBytes = BytesCaller ' Bytes Return FormatNumber(DoubleBytes, 2) & " Bytes" Case Else Return "" End Select Catch Return "" End Try End Function