Main menu

how to delete files older than x days on windows

Many times you need to cleanup your windows system and want to clean files before certain date and time. You can easily find GUI tools to achieve this. But for automation purpose i you can create a batch file with command and and schedule it. It will automatically delete files older than x days on windows system.

forfiles -p "D:\Archive" -s -m *.* -d -7 -c "cmd /c del @path"

forfiles will loop through you files and execute command given command


  • -p : Path of files
  • -s : Search into sub-directory recursively
  • -m: search mask what to find like *.txt for text file. here we can use wild card for better search criteria. *.* means search for every file.
  • -d : days to search -7 means files older then 1 week.
  • -c : what command to execute on searched files.