Delete files from share on files server.

We have a scanner that places Documents in the folder on one of the shares on our file server.  Of course people scan stuff in and then just leave it there.  Is there someway to automatically delete the files in the shares after a week?

Our file server is Windows server 2008.  We are running Active Directory from another 2008 server.
Who is Participating?
NotVeryFatConnect With a Mentor Commented:
Save the following as a VB file (eg delfiles.vbs), then create a batch file with the following line: delfiles.vbs c:\ShareYouWantToDeleteFrom 7

(7 is the number of days)

Set objArgs = WScript.Arguments
FolderName =objArgs(0)

set fso = createobject("scripting.filesystemobject")
set folders = fso.getfolder(FolderName)
datetoday = now()
newdate = dateadd("d", Days*-1, datetoday)
wscript.echo "Today:" & now()
wscript.echo "Started deleting files older than :" & newdate
wscript.echo "________________________________________________"
wscript.echo ""
recurse folders
wscript.echo ""
wscript.echo "Completed deleting files older than :" & newdate
wscript.echo "________________________________________________"

sub recurse( byref folders)
  set subfolders = folders.subfolders
  set files = folders.files
  wscript.echo ""
  wscript.echo "Deleting Files in:" & folders.path
  wscript.echo "__________________________________________________________________________"
  for each file in files
    if file.datelastmodified < newdate then
      wscript.echo "Deleting " & folders.path & "\" & & " last modified: " & file.datelastmodified
      on error resume next
    end if

  for each folder in subfolders
    recurse folder

  set subfolders = nothing
  set files = nothing

end sub
As far as I know there is no windows program to do this, however there is a free software called Cyber-D's Autodelete which can be found here. I use it on my server for a similar use.

Good luck!
NotVeryFatConnect With a Mentor Commented:
... And then schedule the .bat file using Windows Scheduler.

I got this script online years ago and has worked very well ever since (sorry, I don't know where I got it to give credit!)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.