How to delete files more than X days old in Windows CMD

Just a quick post on a really handy command to keep around.


If you have ever needed to script or even just manually delete a bunch of files that were old than X days then you can use the following command in Windows CMD:


forfiles /p “C:\source_folder” /s /m *.* /c “cmd /c Del @path” /d –7


Just make sure you change the path to where your files are and in this example the “/d -7” at the end is deleting files older than 7 days, you can change that number to anything you wish.