Rename many files in a folder with PowerShell

Rename parts of many files using PowerShell.

John Savill

July 21, 2016

1 Min Read
Rename many files in a folder with PowerShell

Q. How can I rename many files in a folder with specific requirements using PowerShell?

A. PowerShell has powerful string manipulation capabilities that can easily be used when renaming bulk files by saving all the target files to an array then performing the rename on each file in the array. In the example below I save all the files to a variable ($files) then for each file in the array its filename has c11 replaced with c12 within that filename.

$files = Get-ChildItem -Path C:Tempforeach ($file in $files) {    $newFileName=$file.Name.Replace("c11","c12")       Rename-Item $file $newFileName}

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like