Solved

VB Script - Empty Recycle Bin

Posted on 2014-01-02
3
600 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
  • 2
3 Comments
 
LVL 21

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now