Hello,
Can someone give me some help on the below VB script. Unfortunately I am not a VB programmer. I need this script to delete files that are 30 days old from a folder call "test" and any subfolders found within the test folder. Once all the old files are deleted, I also want the empty subfolders to be deleted. I do not want the test folder to be deleted only the empty subfolders.
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.
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
fso.DeleteFile(file.Path)
End If
Next
Set folderCollection = folder.SubFolders
For Each subFolder In folderCollection
DeleteOldFiles subFolder.Path, BeforeDate
Next
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
fso.DeleteFolder(folder.Path)
End If
Next
End Function
*****************************************************************