Windows File Explorer cannot replace part of many file names at once. Selecting several files and pressing F2 only gives them all the same base name with (1), (2), (3) added. To replace a word or characters inside many names, use a PowerShell command such as Get-ChildItem -File -Filter '*old*' | Rename-Item -NewName { $_.Name -replace 'old','new' }, or a batch tool that can rename files and folders and show you the new names before anything changes.
This guide covers the Explorer limitation, the PowerShell commands for files and folders, the traps that cause errors or lost files, and how to keep links working when names change.
What File Explorer can and cannot do
- Rename one file: select it, press F2, type the new name.
- Rename many files to a numbered series: select them, press F2, type a name such as
Holiday, press Enter. You getHoliday (1).jpg,Holiday (2).jpgand so on. - Replace part of each name: not possible. There is no find and replace for names in Explorer.
For anything beyond a numbered series, use PowerShell or a dedicated tool.
Replacing text in file names with PowerShell
- In File Explorer, open the folder, click the address bar, type
powershelland press Enter. PowerShell opens in that folder. - Preview the change first by adding
-WhatIf:Get-ChildItem -File -Filter '*draft*' | Rename-Item -NewName { $_.Name -replace 'draft','final' } -WhatIf - Read the list of "What if: Performing the operation Rename File" lines. Each shows the old and new path.
- If it looks right, run the same command again without
-WhatIf.
The -Filter '*draft*' part limits the command to files that actually contain the text, so files that would keep the same name are not touched.
Useful variations
| Goal | Command (inside -NewName { }) |
|---|---|
| Replace spaces with hyphens | $_.Name -replace ' ','-' |
| Replace underscores with spaces | $_.Name -replace '_',' ' |
| Remove a word | $_.Name -replace 'copy of ','' |
| Change a version number | $_.Name -replace 'v\d+\.\d+','v2.0' |
| Change only the name, not the extension | ($_.BaseName -replace 'old','new') + $_.Extension |
| Lowercase the whole name | $_.Name.ToLower() |
Remember that -replace uses regular expressions and ignores case. A dot in the search means "any character", so escape it as \. when you mean a literal dot. Use -creplace if case matters. Removing a prefix such as IMG_ from the start of names only is covered in our guide to removing a prefix from file names on Windows.
Including subfolders
Add -Recurse to Get-ChildItem to rename matching files in every subfolder. Wrap the listing in parentheses so PowerShell collects the full list before renaming starts, which avoids the same file being picked up twice:
(Get-ChildItem -File -Recurse -Filter '*draft*') | Rename-Item -NewName { $_.Name -replace 'draft','final' } -WhatIf
Renaming folders
Use -Directory instead of -File. When renaming folders recursively, rename the deepest folders first. Otherwise renaming a parent changes the path of its children before they are processed, and those renames fail:
Get-ChildItem -Directory -Recurse -Filter '*old*' | Sort-Object { $_.FullName.Length } -Descending | Rename-Item -NewName { $_.Name -replace 'old','new' } -WhatIf
Traps to avoid
- Name collisions. If two files would end up with the same name, the second rename fails with an error that the file already exists. Check the
-WhatIfoutput for duplicates. - Invalid characters. Windows names cannot contain
\ / : * ? " < > |. A replacement that introduces one of these fails. - Changed extensions. A careless pattern can alter the extension, so the file no longer opens with the right program. Use
$_.BaseNameto protect it. - Path length. Very long names deep in a folder tree can exceed the classic 260-character path limit on some systems and tools.
- No undo. PowerShell renames are immediate. Keep the
-WhatIfoutput, or a listing made withGet-ChildItem -Recurse | Select-Object FullName | Export-Csv before.csv, so you can work back if needed.
Common rename recipes
- Web-friendly names: lowercase and hyphens instead of spaces:
($_.Name.ToLower() -replace '\s+','-'). Good for images and downloads on a website. - Remove characters that cause trouble in URLs and scripts, such as
&,#and%:($_.Name -replace '[&#%]',''). - Replace a date format in names, such as
report-31-12-2025.pdftoreport-2025-12-31.pdf:($_.Name -replace '(\d{2})-(\d{2})-(\d{4})','$3-$2-$1'). ISO dates make files sort in date order. - Collapse double spaces or underscores:
($_.Name -replace '_{2,}','_').
Each of these goes inside Rename-Item -NewName { ... }, and each deserves a -WhatIf run first.
Renaming breaks links: update the contents too
File names are often referenced inside other files: image paths in HTML, includes in PHP, imports in code, links in Markdown docs. Rename old-logo.png to new-logo.png and every page that refers to old-logo.png now shows a broken image.
So a rename usually needs a matching content replace:
- Rename the files.
- Replace the old names with the new names in every file that refers to them (for example all
.html,.cssand.mdfiles). - Search for the old names to confirm nothing still refers to them.
Our guide to finding and replacing text in multiple files covers the content side in detail.
Renaming and replacing in one run
Doing the names and the contents as two separate jobs is where things drift out of step. Bulk Replace can replace text in file and folder names, either in the same run as the file contents or on its own. That lets you use Bulk Replace to rename files to a new scheme, strip a prefix or change a version number while updating every reference to them at the same time. Because both happen in one job, the names and the references to them stay in step, and the content changes still go through the usual before/after preview and automatic backup.
Keep a rename log
Before a large rename, save the old names with Get-ChildItem -Recurse -File | Select-Object FullName | Export-Csv names-before.csv -NoTypeInformation. If something breaks later, you can see exactly what each file used to be called.
Quick decision guide
| Job | Best tool |
|---|---|
| Give a set of photos one name with numbers | File Explorer F2 |
| Replace a word in names in one folder, one-off | PowerShell with -WhatIf |
| Rename across subfolders, including folders | PowerShell (deepest first) or a batch tool |
| Rename files and update every reference to them | A tool that renames and replaces contents in one run |
If you need to find which files mention a name before renaming it, see how to find all files containing text on Windows.
Frequently asked questions
Can File Explorer replace part of many file names?
No. Selecting several files and pressing F2 gives them all one base name with (1), (2) numbers. Replacing part of each name needs PowerShell or a rename tool.
What is the PowerShell command to replace text in file names?
Get-ChildItem -File | Rename-Item -NewName { $_.Name -replace 'old','new' } replaces old with new in every file name in the current folder. Add -Recurse to include subfolders.
Will renaming files break links to them?
Yes, if other files refer to them by name. Update the references in the file contents in the same job, then test the links.
