Powershell: How to recursively delete files based of file extension?
File this under “took me WAY too long to figure out how to do”.
I just finished doing a Git merge, and ran into an issue where my working folder was polluted with .orig files.
I wanted to recursively delete all the .orig files. That is apparently harder than it sounds, because it took me 15 minutes to figure out the correct command line.
So you don’t go fumbling like I did:
Get-ChildItem . -recurse -include *.orig | remove-item
Replace . and *.orig accordingly. Have fun!
For more Git tips, check out my default .gitignore file for Visual Studio projects.
About Kevin
Kevin Griffin has been running production .NET applications and teaching developers for over two decades. A 16-time Microsoft MVP specializing in ASP.NET Core and Azure, Kevin brings real-world experience from his own SaaS products alongside his consulting work at Swift Kick. He's hosted the Hampton Roads .NET User Group since 2009 and founded RevolutionVA, the nonprofit behind Hampton Roads DevFest. Kevin's talks blend hard-won lessons from production systems with practical advice you can use Monday morning.
Categories