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.
 
it stops at line 18
Which error message ?
What is the code of line 18 ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It responds Line 18 char 5 " file not found " code 800a0035 which is

Set infoFile = objFSO.GetFile(infoPath)

I dont understand it as i think i have declared all values?

(Sorry for my bad english.)
 
So, just to be sure, put this line of code just before line 18:
Code:
MsgBox "infoPath='" & infoPath & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Response is

infoPath=c:\temp\abcdef\application data info.txt - (abcdef is the first entry in my info.txt file)

I think i have it wrong script written then (or stolen ;-) )

My intention was the script to read the contents of the file info.txt (which contains a list of usernames) then remove only the ones in the this list if they are older 21 days, what did i do wrong
 
read the contents of the file info.txt
Where in your script are you supposed to read this file ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Const strInfo = "info.txt" & If objFSO.GetFile(objUser.Path & "info.txt").Datecreated < (Now() - 21)

was my idea that it reads teh info.txt files for entry's or am i completely missing the point here.
 
Exactly what i needed, many thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top