Delete Files Older Than 90 Days From Batch or Command Line

I have a few scripts that go in and look for files that are older than 90 days and delete them. Here is an example of something to delete zip files older than 90 days in a folder in the Inetpub directory.

The first thing I want to do is see how many files are going to be deleted so I run the following. Notice the “echo” command will make it so it only displays files, not deletes them. This is better for dialing in the command prior to actually having it delete any files. Also notice the find command looks for “1”. Since all of the files I need removed have the date in them, the number 1 is in every file.

forfiles /P "C:\Inetpub\ftproot\StarComm" -s -m *.zip -d -90 -c "cmd /c echo @file" | Find "1" /c

Now to actually remove files older than 90 days.

forfiles /P "C:\inetpub\ftproot\StarComm" -s -m *.zip -d -90 -c "cmd /c del @file"