Help with VB Script

By jutpro ·

Can someone give me some help on the below VB script. Unfortunately I am not a VB programmer.

I pasted together different portions of scripts and the below is the script I have. This script works in deleting all files that are 30 days old from the main folder, 'test", and all subfolders. However, I cannot get it to delete the empty subfolders.

Can someone be so kind as to look at the below script and let me know what needs to be modified to get it to delete the empty subfolders. Note, I do not want the test folder to be deleted only the empty subfolders.

Thanks in advance for your help.

*****************VB Script**************************
Dim fso, startFolder, OlderThanDate

Set fso = CreateObject("Scripting.FileSystemObject"
startFolder = "c:\test"
OlderThanDate = DateAdd("d", -30, Date) ' 30 days

DeleteOldFiles startFolder, OlderThanDate

Function DeleteOldFiles(folderName, BeforeDate)
Dim folder, file, fileCollection, folderCollection, subFolder

Set folder = fso.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection
If file.DateLastModified < BeforeDate Then
End If

Set folderCollection = folder.SubFolders
For Each subFolder In folderCollection
DeleteOldFiles subFolder.Path, BeforeDate
End Function

Function DeleteOldfolder(foldername, BeforeDate)

Set folderlist = fso.GetFolder(foldername)
Set folderCollection = Folderlist.SubFolders
For Each Folder In folderCollection
If folder.DateLastModified < BeforeDate Then
End If
End Function

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

uncalled fucntion

by john.a.wills In reply to Help with VB Script

The function DeleteOldFolder (which should really be a procedure) seems not to get invoked.

Collapse -

Any Help?

by jutpro In reply to uncalled fucntion

I would appreciate any help you can offer in how I can correct this procedure.
I know absolutely nothing about VB Scripting.

The only problem with this script is it does not delete the empty subfolders.


Collapse -

Learn vbscript

by Brenton Keegan In reply to Any Help?

I'd really spend some time to learn vbscript if you're going to try to code a script that deletes files.

Look up "Object Oriented programming", that will help you to really understand the structure.

Collapse -

Here you go.. Script to Delete Empty Folders....

by Peconet Tietokoneet In reply to Help with VB Script
Collapse -

Thanks to all

by jutpro In reply to Here you go.. Script to D ...

Thanks to everyone. I was able to get the script to work fine.

Related Discussions

Related Forums