Need a command to delete files/ directories older than 7 days on Windows 2008r2 Server

We have a directory on a fileserver that users scan documents to.  It is suppose to be a temporary area, but users do not clean up the files.  The server path is:


I would need all files and subdirectories older than 7 days to be deleted.  I am not a script person or a programmer so I not sure how to do this.

Any help would be appreciated.
Who is Participating?
John KilgoreConnect With a Mentor Commented:
This should assist:

1) Using ForFiles to delete files over 7 days old:

C:\> forfiles /p "C:\source_folder" /s /m *.* /c "cmd /c Del @path" /d -7

2) Using Robocopy /Move to delete files over 7 days old:

C:\> set _robodel=%TEMP%\~robodel
C:\> MD %_robodel%
C:\> ROBOCOPY "C:\source_folder" %_robodel% /move /minage:7
C:\> del %_robodel% /q

3) Using DateMath.cmd and Getdate.cmd, download DelOlder.cmd

4) With PowerShell delete files over 7 days old:
PS C:\> $now = get-date
PS C:\> dir "C:\source_folder\" | where {$_.LastWriteTime -le $now.AddDays(-7)} | del -whatif
cobpAuthor Commented:
Thank you Itguy565 :)
Bill PrewCommented:
Also be aware of a great lightweight utility for this called delage32.

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.