VBS to automatically delete FOLDERS

I am trying to create a .vbs that deletes FOLDERS. I do not want to use 3rd-party deletion software such as DELENDA or DELOLD. I also do not want to use Powershell. I have searched for this topic on EE but all the scripts concentrate on files within folders. I only need to delete the folders.

I will be executing the script using a scheduled task.

Here is an example of the folder paths (notice there are spaces in the folder name):

d:\BakupDest\Fri 02.01.2008, 12:30
d:\BakupDest\Sun 02.03.2008, 12:30
d:\BakupDest\Mon 02.04.2008, 12:30

I would like a script that deletes the subfolders of d:\BakupDest\ if they are older than thirty days, by last modified date.

The .vbs below works for files (using last created date) but not for FOLDERS. I have tried changing the methods to Folders instead of files or file but I keep getting script errors. I would like the vbs to perform the same function as the script below but for FOLDERS and modified date of the folder.

'-------------- FILEDELETE.vbs --------------------
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("c:\PathofMyFolder\")
Sub DeleteFiles(srcFolder)
Dim srcFile
If srcFolder.Files.Count = 0 Then
Exit Sub
End If
For Each srcFile in srcFolder.Files
If DateDiff("d", Now, srcFile.DateCreated) < -30 Then
fso.DeleteFile srcFile, True
End If
End Sub

Thank you for your time.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try using the remove directory command (rmdir). Example:

RmDir "C:\bakupdest\sun\"
For others that may be reading this post down the line. Look away "Jeremy_in_Japan"

The Powershell version

get-childitem C:\bakupdest | ?{$_.PSIscontainer -and ($_.LastWriteTime -lt (Get-date).addmonths(-1))} | remove-item -whatif
Jeremy_in_JapanAuthor Commented:
Thanks for your comment BSonPosh.

I have tested and successfully used the Powershell version that you listed. Unfortunately, my organization doesn't want to install and use it on their servers - at this time anyway.

For those of you who aren't restricted, Powershell  is soooo much easier to use! Listen to BsonPosh! :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeremy, I understand completely.

Do you know Powershell works perfectly fine using remote filesystem? This means you can use UNC from your machine to accomplish this task.

get-childitem \\server\C$\bakupdest | ?{$_.PSIscontainer -and ($_.LastWriteTime -lt (Get-date).addmonths(-1))} | remove-item -whatif

Anyway... GL with the vbscript version and work on those Powershell hold outs :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.