Skip navigation
Rename many files in a folder with PowerShell

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:\Temp
foreach ($file in $files) 
{
    $newFileName=$file.Name.Replace("c11","c12")   
    Rename-Item $file $newFileName
}

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish