How to delete files older than x

Something I regularly need to do is search for files that are older than a certain amount of time and do something with them, like move or delete. Here’s a handy snippet how to do it in PoSh.

The question mark is an alias for Where-Object, -le means “less than or equal”, and AddMinutes has close relatives like AddDays… just use the autocomplete via the tab key after “Add” to get more.

2 thoughts to “How to delete files older than x”

  1. Oh, and the same on linux:

  2. Today I found out that doing it this way is a whole lot faster, in case the directory contains a huge number of files:

    Thx, Sarath.

Comments are closed.