Removing Unwanted Files with PowerShell

Sometimes after using gVim on Windows, I end up with temporary files.


I’d really like to remove all the files in .\content that end in ~. If find on Unix immediately comes to mind, PowerShell’s Get-ChildItem will feel right at home.

Get-ChildItem -Path .\content -Filter *~ -File | Remove-Item

Our directory is free from unwanted files!

Note It’s also possible to directly use the Remove-Item command, but by using Get-ChildItem we can safely fine-tune our query before piping it to the destructive Remove-Item.

Published Sep 28, 2014