VBS: Delete Folders
This script can be used to delete folders that are older then a defined ammount of days!
! This script is no longer maintained !
Script code:
'######################################
'
' SH-Soft.com
' DeleteFolders.vbs
'######################################
'
' created by Martin Mueller
' martin.mueller@sh-soft.com
'
'######################################
'
Version = "1.0.0.0"
' Last Modified: 20070912
' First Release: 20070912
'
'######################################
'
'
'On Error Resume Next
'*** Global settings ***
Set fso = CreateObject("Scripting.FileSystemObject")
Set logfile = fso.CreateTextFile("C:\folderdelete-"& Year(DATE) & Month(DATE) & Day(DATE) &".log", True)
'***************************************************************************************
'* Collect Data
NumberDays = 7
strPath = "---"
'***************************************************************************************
'* Header
WriteLog " SH-Soft.com Delete Folder Script"
WriteLog ""
WriteLog " created by Martin Müller"
WriteLog " martin.mueller@sh-soft.com"
WriteLog ""
WriteLog " - Version: "& Version
WriteLog " - Deleting files older then "& NumberDays &" (days)"
WriteLog " - Searching folder: "& strPath
WriteLog ""
WriteLog ""
'***************************************************************************************
'* Start Program
DeleteFolders
'******************************************************************
'* DeleteFolders
'*
'* Version: 1.0.0
'* Last Modified: 20070912
'******************************************************************
SUB DeleteFolders
IF fso.FolderExists(strPath) THEN
Set objFolder = fso.GetFolder(strPath)
Set colSubfolders = objFolder.Subfolders
dateToday = Now()
cntDelteFolders = 0
FOR EACH objSubfolder IN colSubfolders
WriteLog "Folder Name: "& objSubfolder.Name
WriteLog " created: "& objSubfolder.DateCreated
'WriteLog " modified: "& objSubfolder.DateLastModified
dateFolder = objSubfolder.DateCreated
IF dateFolder <= dateToday THEN
daysOld = dateToday - dateFolder
IF daysOld > NumberDays THEN
cntDelteFolders = cntDelteFolders + 1
WriteLog " --> Folder deleted: "& strPath &"\"& objSubfolder.Name &" !"
fso.DeleteFolder(strPath &"\"& objSubfolder.Name)
ELSE
WriteLog " <-- This folder can stay here"
END IF
END IF
NEXT
WriteLog ""
WriteLog ""
WriteLog "################################################"
WriteLog " Folders deleted: "& cntDelteFolders
ELSE
WriteLog "Folder does not exist:"& strPath &" stopping!"
END IF
END SUB
'******************************************************************
'* WriteLog
'*
'* Version: 1.1.1
'* Last Modified: 20070502
'******************************************************************
SUB WriteLog (LogEntry)
logfile.WriteLine(NOW() &" - "& LogEntry)
END SUB