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.
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.