Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for deltrash2.vbs

(view source code of deltrash2.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim intItems, intSize, objBin, strMsg
  4.  
  5. ' Get BinManager object
  6. Set objBin = CreateObject( "BinManager.RecycleBin" )
  7.  
  8. intItems = objBin.NumItems
  9. intSize  = objBin.Size
  10.  
  11. Select Case WScript.Arguments.Named.Count
  12. 	Case 0
  13. 		' This is ok, it means empty the Recycle Bin
  14. 	Case 1
  15. 		' /Q would be the only valid argument
  16. 		If Not WScript.Arguments.Named.Exists( "Q" ) Then Syntax
  17. 	Case Else
  18. 		Syntax
  19. End Select
  20.  
  21. Select Case WScript.Arguments.Unnamed.Count
  22. 	Case 0
  23. 		objBin.Empty
  24. 		If Not WScript.Arguments.Named.Exists( "Q" ) Then Report
  25. 	Case 1
  26. 		If IsNumeric( WScript.Arguments.Unnamed(0) ) Then
  27. 			objBin.DeleteOldItems CInt( WScript.Arguments.Unnamed(0) )
  28. 		If Not WScript.Arguments.Named.Exists( "Q" ) Then Report
  29. 		Else
  30. 			Syntax
  31. 		End If
  32. 	Case Else
  33. 		Syntax
  34. End Select
  35.  
  36.  
  37. ' Report the contents of the recycle bin.
  38. Sub Report( )
  39. 	strMsg  = CStr( intItems - objBin.NumItems ) _
  40. 	        & " items were removed from the Recycle Bin (" _
  41. 	        & FormatNumber( ( intSize - objBin.Size ) / 1048576, 1, True, False, False ) _
  42. 	        & " MB)" & vbCrLf
  43. 	intSize = FormatNumber( objBin.Size / 1048576, 1, True, False, False )
  44. 	WScript.Echo strMsg & "The Recycle Bin still holds " & objBin.NumItems _
  45. 	           & " items (" & intSize & " MB)"
  46. End Sub
  47.  
  48.  
  49. Sub Syntax
  50. 	strMsg = vbCrLf _
  51. 	       & "DelTrash2.vbs,  Version 1.00" & vbCrLf _
  52. 	       & "Empty the Recycle Bin, or remove only files" & vbCrLf _
  53. 	       & "older than the specified number of days" & vbCrLf & vbCrLf _
  54. 	       & "Usage:  DELTRASH2.VBS  [ days ]  [ /Q ]" & vbCrLf & vbCrLf _
  55. 	       & "Where:  days  is the minimum age in full calendar days of files to be deleted" & vbCrLf _
  56. 	       & "              (0 means delete everything older than today)" & vbCrLf _
  57. 	       & "        /Q    suppresses screen output (number of items and MBs)" & vbCrLf & vbCrLf _
  58. 	       & "Notes:  [1]   This script requires BinManager by Tim Tabor" & vbCrLf _
  59. 	       & "              http://www.cheztabor.com/BinManager/" & vbCrLf _
  60. 	       & "        [2]   This script was based on Tim Tabor's own JScript sample" & vbCrLf & vbCrLf _
  61. 	       & "Written by Rob van der Woude" & vbCrLf _
  62. 	       & "http://www.robvanderwoude.com" & vbCrLf
  63. 	WScript.Echo strMsg
  64. 	Report
  65. 	WScript.Quit 1
  66. End Sub
  67.  

page last modified: 2024-04-16; loaded in 0.0070 seconds