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

Script for home directory clean-up

Status
Not open for further replies.
May 12, 2004
99
US
I work at a school and need to empty student home directories at the end of the school year. Is there something that will accomplish this? Any help would be appreciated. Thanks.
 
Need to know more. By "empty" do you mean delete the directories or just the contents?

You can use the file system object to bind to the folders, and enumerate/delete the files and subfolders.

Do a search in this forum for CleanBadMail.vbs. It is a scritp I wrote that will do the above and delete files based on age. You could either remove the age checking or set you value to delete anything older than 1 day.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Try This

Code:
Option Explicit
On Error Resume Next

'Declare variables
Dim objFSO, oSubFolder, oFolder1, oSubFolder1, colSubfolders1, oFile

'Set up environment

Set objFSO = CreateObject("Scripting.FileSystemObject")

'start deleting files
Set oFolder1 = objFSO.GetFolder("home folder location")
  For Each oFile In oFolder1.files
       oFile.Delete True
  Next
'Delete folders and subfolders
Set colSubfolders1 = oFolder1.Subfolders
  For Each oSubfolder in colSubfolders1
       objFSO.DeleteFolder oSubFolder.path,True
  Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top