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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete User folder that havent been accessed over60 days

Status
Not open for further replies.

Atterz

Technical User
Jul 6, 2010
2
GB
First off, im new to these forums and this is my first post, so . . . . HEY ALL :)

Hopefully someone can help as its starting to do my head in now.

I need help in creating a script that will delete user folders that havent been accessed/modified in 60 days but not to delete specified folders e.g. Administrator.

I am a novice at scripting, so please be gentle :)

Thanks in advance

Atterz
 
What have YOU tried so far and where in YOUR code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry forgot to add it in. Here is my code. This deletes all the folders that havent been accessed in 60 days inc admin folders.

I tried writing a script to create a file in some folders so they had been modified but for some reason it still deleted the folder



'Set the following variables
TempFolderPath = "C:\Documents and Settings" 'no trailing backslash
NumberOfDays = 60 'anything older than this many days will be removed

'Set objects & error catching
On Error Resume Next
Dim fso
Dim objFolder
Dim objFile
Dim objSubfolder
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(TempFolderPath)

'DELETE all files in TempFolder Path older than x days
For Each objFile In objFolder.files
If DateDiff("d", objFile.DateCreated,Now) > NumberOfDays Then
objFile.Delete True
End If
Next

'DELETE all subfolders in TempFolder Path older than x days
For Each objSubfolder In objFolder.Subfolders
If DateDiff("d", objSubfolder.DateCreated,Now) > NumberOfDays Then
objSubfolder.Delete True
End If
Next
 
'DELETE all subfolders in TempFolder Path older than x days
For Each objSubfolder In objFolder.Subfolders
If objSubfolder.Name <> "Administrator" Then
If DateDiff("d", objSubfolder.DateCreated,Now) > NumberOfDays Then
objSubfolder.Delete True
End If
End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top