forfiles – Remove Files older than XX days on Windows 2008

Ever wanted to remove files older than XX days and have it run as a sheduled task on Windows 2008 Server ?

Create a .bat file and paste the following into it, save it and add it as a Scheduled Task in Control Panel


forfiles /p c:\path\to\folder /s /m *.* /d -XX /c "cmd /c del /Q /S /F @file"

Easy huh :)

Leave a Reply