Solved

VB Script - Empty Recycle Bin

Posted on 2014-01-02
3
617 Views
Last Modified: 2014-01-07
Hi

I have a VB Script that cleans up various things on the C drives of servers.  The only part I am having trouble with is cleaning the recycle bin.  Here is the sub that I have that isn't working:

SUB Recycle (strComputer, StrDrive)

strDrive1 = Left(strDrive, 1)
Set FSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "\\" & strComputer & "\" & strDrive1 & "$\RECYCLER"
If Not FSO.FolderExists(sDirectoryPath) Then
    sDirectoryPath = "\\" & strComputer & "\" & strDrive1 & "$\$Recycle.Bin"
End If

Set objFolder = FSO.GetFolder(sDirectorypath)
 
CALL DeleteFiles (objFolder)

END SUB
'______________________________________________________________________________________
SUB DeleteFiles(objFolder)
   For Each objFile in objFolder.Files
      Wscript.Echo objFile.Path
      objFile.Delete True
   Next

   For Each objSubFolder In objFolder.Subfolders
      DeleteFiles(objSubFolder)
   Next
END SUB

Maybe having two subs is creating the issue?  Any help is appreciated.

Tony
0
Comment
Question by:tonyjoewalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Assisted Solution

by:dan_blagut
dan_blagut earned 500 total points
ID: 39751109
0
 

Accepted Solution

by:
tonyjoewalker earned 0 total points
ID: 39752160
I changed to code to:

For Each objSubFolder In objFolder.Subfolders
      objSubFolder.delete
Next

and now everything works.
0
 

Author Closing Comment

by:tonyjoewalker
ID: 39761650
I figured out the adjustment I needed to my existing code.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
GPO on certain users 17 38
using vb script 5 52
Configuring DNS Round Robin in Windows DNS server ? 8 77
IIS Authentication Error 401 16 17
A procedure for exporting installed hotfix details of remote computers using powershell
A safe way to clean winsxs folder from your windows server 2008 R2 editions
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question