Tuesday, December 13, 2011

Deleting files, keeping a few

Inspired by this post, how it works in PowerShell:

Get-ChildItem *.log | Sort-Object lastWriteTimeUtc -descending | Select-Object -skip 3 | Remove-Item
view raw gistfile1.ps1 hosted with ❤ by GitHub

will delete all but the most recent 3 files ending in ".log"; and it would be the same sort of thing in any scripting language.

No comments :