Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello everyone, first post, and not any easy one..
I currently have a script from a few examples that I mashed together that works wonderfully to delete folders and it's contents based on a date older than X. Great for use on a login script, but slows down the users log in time.
I need this same script to do the same thing for many user accounts (in place of strUserName) or possibly a loop of the same script changing the strUserName focus.
example:
C:\Documents and Settings\User1\cookies
C:\Documents and Settings\User2\cookies
C:\Documents and Settings\User3\cookies
C:\Documents and Settings\User4\cookiesHere is a copy of what I currently have:
Dim objNetwork
Dim strFolderLocation, strUserName, strTargetFolder' gets name of local user account for use in path
Set objNetwork = WScript.CreateObject("WScript.Network")
strUserName = objNetwork.UserName' name of folder location (not including username)
strFolderLocation = "C:\Documents and Settings\"' name of target folder (after username folder)
strTargetFolder = "\cookies"' set to false for testing purposes
Const Active = true'number of days old you would like to filter
Const MaxAge = 2 'daysConst Recursive = true
Checked = 0
Deleted = 0Set oFSO = CreateObject("Scripting.FileSystemObject")
if active then verb = "Deleting """ Else verb = "Old file: """''CheckFolder oFso.GetFolder(strFolderLocation & strUserName & strTargetFolder)
CheckFolder oFso.GetFolder(strFolderLocation)' *** Mark out the below line to prevent the script prompting you for each file/folder ***
' WScript.echoif Active then verb = " file(s) deleted" Else verb = " file(s) would be deleted"
' *** Mark out the below line to prevent the script prompting you for each file/folder ***
' WScript.Echo Checked & " file(s) checked, " & Deleted & verb
Sub CheckFolder (oFldr)
For Each oFile In oFldr.Files
Checked = Checked + 1
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then
Deleted = Deleted + 1' *** Mark out the below line to prevent the script prompting you for each file/folder ***
' WScript.Echo verb & oFile.Path & """"If Active Then oFile.Delete
End If
Nextif not Recursive then Exit Sub
For Each oSubfolder In oFldr.Subfolders
CheckFolder(oSubfolder)
Next
End Sub
Any ideas would be greatly appreciated!
Z

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |