[Windows] Batch command for deleting files older than N days
So I need to automate files deletion on specific directories which are older than N days, using CMD only.
Here’s how I did it. Use below command.
FORFILES /p [directory_path] /d [N_days] /m [file_filter] /c [command]
Example. I want to delete all Excel files inside D:/test folder which are older than 5 days.
FORFILES /p "D:/test" /d -5 /m *.xlsx /c "cmd /c del @file"