Solved

VB Script - Empty Recycle Bin

Posted on 2014-01-02
3
606 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
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 the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

920 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

13 Experts available now in Live!

Get 1:1 Help Now