Bulk rename files using PowerShell

How many times have you wanted to rename files en-masse? Windows Explorer has a couple of great utilities to help with this task. For instance:

  1. Select files in Explorer using CTRL or SHIFT (files must be in the same folder)
  2. Press F2 to rename, or right-click -> rename
  3. Type the new name for the files.
  4. The files are renamed in sequence, with (1), (2)… (n) being appended to the name you entered

clip_image002

This is great, until you want to rename files in different folders to the same name. For example:

– Root
| – Folder 1
| | – File 1.txt
| | – File 2.txt
| | – File n.txt
| – Folder 2
| | – File 1.txt
| | – File 2.txt
| | – File n.txt
| – Folder 3
| | – File 1.txt
| | – File 2.txt
| | – File n.txt

Here, the normal multi-select isn’t possible, even if you perform a search. Instead, a quick PowerShell command lets us find and rename files in these subfolders.

Find the files in subfolders:

get-childitem -recurse -filter “File 1.txt” | foreach { $_.fullname}

This will display the full path of each file that you want to rename. Once you’re happy, pipe the results into the rename-item cmdlet:

get-childitem -recurse -filter “File 1.txt” | foreach {rename-item -path $_.fullname -newname “Renamed File 1.txt”}

This will search the current folder and subfolders, rename any files called ‘file 1.txt’ to ‘renamed file1.txt’

Leave a Reply

Your email address will not be published. Required fields are marked *