?
Solved

VB Script - Empty Recycle Bin

Posted on 2014-01-02
3
Medium Priority
?
620 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 2000 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
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…
Suggested Courses

752 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