Bulk-Changing File Extensions

by Aug 11, 2010

Changing file extensions can be a quick one-line operation. The next line renames all ps1 PowerShell script files found in your user profile and renames them to the new extension “old.ps1.” This way, they stay PowerShell scripts, but get an “old” tag.

Dir $home\ *.ps1 -recurse | Foreach-Object { Rename-Item $_.FullName ([System.IO.Path]::GetFileNameWithoutExtension($_.FullName) + “.old.ps1”) -whatif }

You need to make sure to remove -whatif to actually do the renaming, and remove the -recurse parameter if you do not want to traverse subfolders.

Twitter This Tip! ReTweet this Tip!