im looking for a script that will delete old files and folders from some temp locations we have and a couple of other locations.
i have found the code below on this site, which is great for deleting files older then 24hrs.
but it doesnt remove the folders.
my vbs scripting knowledge is very poor so i have no idea how to modify this script so it removes the old folders as well.
or does anybody have a script that i can run after this one that will remove the folders as well??
strRoot = "c:\VMLocal\backup"
strMask = "*.*"
blnSubFolders = True
intHours = 24
strCommand = "cmd /c @echo off & dir " & Chr(34) & _
strRoot & "\" & strMask & Chr(34) & " /a:-d /b"
If blnSubFolders Then
strCommand = strCommand & " /s"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec(strCommand)
Set objStdOut = objWshScriptExec.StdOut
Do Until objStdOut.AtEndOfStream
strFile = objStdOut.ReadLine
If Not blnSubFolders Then
strFile = strRoot & "\" & strFile
Set objFile = objFSO.GetFile(strFile)
If DateDiff("h", objFile.DateLastModified, Now) > intHours Then
WScript.Echo "Delete " & strFile