Solved

VB Script - Empty Recycle Bin

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

705 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