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