How to Change File Extension for all Files in a Folder

PROBLEM: You have a directory with many files and would like to change the extension on many of them without having to do one by one.

SOLUTION: You can solve this problem with PowerShell and in less than 3 lines of code.

CLEAR
CD [PATH TO FILE LOCATION]
Get-ChildItem *.[FILE EXTENSION]|Rename-Item –NewName {$_.Name –replace "[FROM VALUE]","[TO VALUE]"}

I always like to clear my console and that is what the CLEAR command does.  I will then change to the directory where the files are located and execute my one liner that will change the file extensions of many files.   Here’s an example of how to change the file extensions from .TAB to .SQL.

CLEAR
CD C:DatabaseScripts
Get-ChildItem *.TAB|Rename-Item -NewName { `
    $_.Name -replace "TAB","SQL"
}

In Spanish

Leave a Reply