Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete files and folders older then 21 days

Status
Not open for further replies.

Sliderr

Technical User
Jul 30, 2013
6
0
0
GB
Hi all, please excuse me that i am a NOOB on VBS scripting. I have put together a script (stolen from google) and modified it to do what i wanted.

EG - read a txt file containing username's, from this check if the userfolder is older then 21 days if so delete it, I have this sofar but it stops at line 18 which i cannot get my head around why.. is there anyone can help me with this?
===================================

Const strPath = "c:\temp"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const strInfo = "info.txt"

Set objLogfile = CreateObject("Scripting.FileSystemObject")
Set objLog = objLogfile.OpenTextFile("c:\temp\log.txt", 8, True) ' 8=append, 2=overwrite

Call Search (strPath)
WScript.Echo "Done."
objlog.close

Sub Search(str)
Dim objDept, objUser,
For Each objDept In objFSO.GetFolder(strPath).SubFolders
For Each objUser In objDept.SubFolders
infoPath = objDept & "\" & objUser.Name & "\" & strInfo
Set infoFile = objFSO.GetFile(infoPath)
If objFSO.GetFile(objUser.Path & "info.txt").Datecreated < (Now() - 21) Then
wscript.echo infoPath
'objUser.Delete True
'objLog.Writeline(Now() & " Deleted user folder: " & objUser.Name)
End If
Next
Next

=========================

Many thanks.
Slider.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top