با سلام و تبریک میلاد حضرت علی (ع)
امروز نحوه کار با سطل زباله وندوز رو براتون میذارم:
کد زیر را داخل یک ماژول ذخیره کنید:
Private Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Private Type SHQUERYRBINFO
cbSize As Long
i64Size As ULARGE_INTEGER
i64NumItems As ULARGE_INTEGER
End Type
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hWnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Const SHERB_NOPROGRESSUI = &H1
Private Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHQUERYRBINFO) As Long
Private Declare Function StrFormatByteSize Lib "shlwapi" Alias "StrFormatByteSizeA" (ByVal dw As Long, ByVal pszBuf As String, ByRef cchBuf As Long) As String
Function Get_Empty_Recyclebin()
retvaL = SHEmptyRecycleBin(1, "", SHERB_NOPROGRESSUI)
End Function
Function Get_Recyclebin_size()
Dim RBinInfo As SHQUERYRBINFO
RBinInfo.cbSize = Len(RBinInfo)
SHQueryRecycleBin vbNullString, RBinInfo
Get_Recyclebin_size = FormatKB(RBinInfo.i64Size.LowPart)
End Function
Function Get_Recyclebin_Items()
Const RECYCLE_BIN = &HA&
Dim a As Shell32.Folder "Required: References> Microsoft Shell Controls And Automation
Set objShell = Create("Shell.Application")
Set a = objShell.NameSpace(RECYCLE_BIN)
Get_Recyclebin_Items = a.Items.Count
End Function
Public Function FormatKB(ByVal Amount As Long) As String
Dim Buffer As String
Dim Result As String
Buffer = Space$(255)
Result = StrFormatByteSize(Amount, Buffer, Len(Buffer))
If InStr(Result, vbNullChar) > 1 Then
FormatKB = Left$(Result, InStr(Result, vbNullChar) - 1)
End If
End Function
-اطلاع از حجم سطل زباله با Get_Recyclebin_size
-اطلاع از تعداد فایلهای موجود در سطل زباله با Get_Recyclebin_Items
-حذف محتویات سطل زباله با Get_Empty_Recyclebin
