Emptying Recycle Bin by VBScript
Moderators: JRL, Dorian (MJT support)
Emptying Recycle Bin by VBScript
Would you please show us a script to empty Windows Recycle Bin with a minimal number of VBScript statements? Many thanks in advance.
Hi Armstrong,
I've found this.
(C) 2001 T.Weltner - Scripting Host - Franzis ISBN 3-7723-7656-8
Please check if "Empty Recycle Bin" matches the option given on your Recycle Bin Context Menu and replace it if necessary.
Rgds,
Ernest
I've found this.
Code: Select all
VBSTART
Sub EmptyRecycler
set shell = CreateObject("Shell.Application")
set folder = shell.NameSpace("C:\")
set item = folder.ParseName("RECYCLED")
item.InvokeVerb "Empty Recycle Bin"
End Sub
VBEND
Please check if "Empty Recycle Bin" matches the option given on your Recycle Bin Context Menu and replace it if necessary.
Rgds,
Ernest
Newbie: The code doesn't run!
Hi.
I'm a newbie of macro scheduler and vb script.
I copy the code in this macro
VBSTART
Sub EmptyRecycler
set shell = CreateObject("Shell.Application")
set folder = shell.NameSpace("C:\")
set item = folder.ParseName("RECYCLED")
item.InvokeVerb "Empty Recycle Bin"
End Sub
VBEND
VBRun>EmptyRecycler
but a message error appear like this:
;-2147024894
Line5,column 5
Please help me!
Thank you
Vittorio d'Alessandro
I'm a newbie of macro scheduler and vb script.
I copy the code in this macro
VBSTART
Sub EmptyRecycler
set shell = CreateObject("Shell.Application")
set folder = shell.NameSpace("C:\")
set item = folder.ParseName("RECYCLED")
item.InvokeVerb "Empty Recycle Bin"
End Sub
VBEND
VBRun>EmptyRecycler
but a message error appear like this:
;-2147024894
Line5,column 5
Please help me!
Thank you
Vittorio d'Alessandro
Hi,
This does it in VBScript but unfortunately asks for confirmation:
VBSTART
Sub EmptyRecycler
Dim oShell
Dim oShellFolder
Const ssfDESKTOP = 0
Set oShell = CreateObject("Shell.Application")
Set oShFolder = oShell.Namespace(ssfDESKTOP)
For Each oShFolderItem In oShFolder.Items
If oShFolderItem.Name = "Recycle Bin" Then
oShFolderItem.InvokeVerb("Empty Recycle &Bin")
Exit For
End If
Next
Set oShell = Nothing
Set oShFolder = Nothing
End Sub
VBEND
VBRun>EmptyRecycler
But this is much easier using DOS:
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd.exe /c rd /s /q c:\recycler
This does it in VBScript but unfortunately asks for confirmation:
VBSTART
Sub EmptyRecycler
Dim oShell
Dim oShellFolder
Const ssfDESKTOP = 0
Set oShell = CreateObject("Shell.Application")
Set oShFolder = oShell.Namespace(ssfDESKTOP)
For Each oShFolderItem In oShFolder.Items
If oShFolderItem.Name = "Recycle Bin" Then
oShFolderItem.InvokeVerb("Empty Recycle &Bin")
Exit For
End If
Next
Set oShell = Nothing
Set oShFolder = Nothing
End Sub
VBEND
VBRun>EmptyRecycler
But this is much easier using DOS:
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd.exe /c rd /s /q c:\recycler
MJT Net Support
[email protected]
[email protected]
Dear Support,
1. c:\Recycler doesn't appear to be a physical directory like other regular directories. As such, would such deletion creates system instability?
2. Even though it's supposed to be self-generated if missing during the Windows bootup, sometimes it fails to do so especially if we have a corrupt Windows registry.
3. Given the fact that c:\recycler is a system directory, can it be deleted by RD?
Look forward to your enlightenment. Thanks.
With due respect, allow me to raise several questions:Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd.exe /c rd /s /q c:\recycler
1. c:\Recycler doesn't appear to be a physical directory like other regular directories. As such, would such deletion creates system instability?
2. Even though it's supposed to be self-generated if missing during the Windows bootup, sometimes it fails to do so especially if we have a corrupt Windows registry.
3. Given the fact that c:\recycler is a system directory, can it be deleted by RD?
Look forward to your enlightenment. Thanks.
Hi,
The c:\recycler directory does not show up but does exist. It is simply hidden by default. In Windows Explorer under Tools/Folder Options you can elect not to hide system files and folders and you will now see that the recycler folder appears.
You will notice that each user's deleted files exist under different coded directories - one for each user.
I use this technique with no problems and the directory is always recreated. But if you don't want to remove the directory you could just delete it's contents instead using:
c:\
cd recycler
del /q /s *.*
The c:\recycler directory does not show up but does exist. It is simply hidden by default. In Windows Explorer under Tools/Folder Options you can elect not to hide system files and folders and you will now see that the recycler folder appears.
You will notice that each user's deleted files exist under different coded directories - one for each user.
I use this technique with no problems and the directory is always recreated. But if you don't want to remove the directory you could just delete it's contents instead using:
c:\
cd recycler
del /q /s *.*
MJT Net Support
[email protected]
[email protected]
Thanks
Hi. Thank you .
I've modified your version for the italian language and it works.
This is the code for win2k in It. lang.:
VBSTART
Sub EmptyRecycler
Dim oShell
Dim oShellFolder
Const ssfDESKTOP = 0
Set oShell = CreateObject("Shell.Application")
Set oShFolder = oShell.Namespace(ssfDESKTOP)
For Each oShFolderItem In oShFolder.Items
If oShFolderItem.Name = "Cestino" Then
oShFolderItem.InvokeVerb("S&vuota Cestino")
Exit For
End If
Next
Set oShell = Nothing
Set oShFolder = Nothing
End Sub
VBEND
VBRun>EmptyRecycler
But now I would create a new excel sheet in VB script and I wrote this simple code but it doesn't work, with th same code error.Do you know the reasons?
Thank you again
the code is:
VBSTART
Sub Chiamata
Dim ExcelSheet
Set ExcelSheet = CreateObject("Excel.Sheet")
ExcelSheet.Application.Visible - True
ExcelSheet.ActiveSheetCells(1,1).Value = "This is the column A, row 1"
ExcelSheet.SaveAs "C:\2003\prova4.xls"
ExcelSheet.Application.Quit
Set ExcelSheet = Nothing
End Sub
VBEND
VBRun>Chiamata
I've modified your version for the italian language and it works.
This is the code for win2k in It. lang.:
VBSTART
Sub EmptyRecycler
Dim oShell
Dim oShellFolder
Const ssfDESKTOP = 0
Set oShell = CreateObject("Shell.Application")
Set oShFolder = oShell.Namespace(ssfDESKTOP)
For Each oShFolderItem In oShFolder.Items
If oShFolderItem.Name = "Cestino" Then
oShFolderItem.InvokeVerb("S&vuota Cestino")
Exit For
End If
Next
Set oShell = Nothing
Set oShFolder = Nothing
End Sub
VBEND
VBRun>EmptyRecycler
But now I would create a new excel sheet in VB script and I wrote this simple code but it doesn't work, with th same code error.Do you know the reasons?
Thank you again
the code is:
VBSTART
Sub Chiamata
Dim ExcelSheet
Set ExcelSheet = CreateObject("Excel.Sheet")
ExcelSheet.Application.Visible - True
ExcelSheet.ActiveSheetCells(1,1).Value = "This is the column A, row 1"
ExcelSheet.SaveAs "C:\2003\prova4.xls"
ExcelSheet.Application.Quit
Set ExcelSheet = Nothing
End Sub
VBEND
VBRun>Chiamata
Hi,
You need to first create the XL application as the sheet is a property of the workbook property of the application. I have rewritten your code to make it work, as follows:
VBSTART
Sub Chiamata
Dim xlApp
Dim xlBook
Dim xlSheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Application.Visible = True
xlSheet.Cells(1,1).Value = "This is the column A, row 1"
xlSheet.SaveAs "C:\2003\prova4.xls"
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
VBEND
VBRun>Chiamata
You need to first create the XL application as the sheet is a property of the workbook property of the application. I have rewritten your code to make it work, as follows:
VBSTART
Sub Chiamata
Dim xlApp
Dim xlBook
Dim xlSheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Application.Visible = True
xlSheet.Cells(1,1).Value = "This is the column A, row 1"
xlSheet.SaveAs "C:\2003\prova4.xls"
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
VBEND
VBRun>Chiamata
MJT Net Support
[email protected]
[email protected]
Having done this I could also have replaced:
xlSheet.Application.Visible = True
with
xlApp.Visible = True
Which is a bit neater.
xlSheet.Application.Visible = True
with
xlApp.Visible = True
Which is a bit neater.
MJT Net Support
[email protected]
[email protected]