Deleting files, keeping a few
Inspired by this post, how it works in PowerShell:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ChildItem *.log | Sort-Object lastWriteTimeUtc -descending | Select-Object -skip 3 | Remove-Item |
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 :
Post a Comment