How do I delete file types of a certain age?

green

This one liner will find all .txt files created more than 50 hours ago (make sure you change the path):

oldfiles

You could easily adjust the file type by replacing txt with whatever you like, as well as adjust the time range.  If you wanted to search based on the last modified date, you could replace $_.creationtime with $_.lastwritetime.

 

To have PowerShell delete files, you can just replace ft (Format-Table) with the Remove-Item cmdlet at the end:

 

Caution with this one – it has the power to cause havoc.

green

Leave a Reply

Your email address will not be published. Required fields are marked *