To remove a prefix from many file names on Windows, open PowerShell in the folder and run Get-ChildItem -File | Rename-Item -NewName { $_.Name -replace '^IMG_','' }. The ^ anchor makes sure only IMG_ at the very start of each name is removed. To remove a suffix such as _final while keeping the extension, use $_.Name -replace '_final(?=\.[^.]+$)',''. Add -WhatIf to Rename-Item first to see what would happen without renaming anything.
File Explorer cannot do this on its own: selecting several files and pressing F2 gives them all the same name with a number. Below are the PowerShell commands for the common cases, the traps to avoid, and a safer route when the names are referenced inside other files.
Step by step: remove a prefix with PowerShell
- Open the folder in File Explorer, click the address bar, type
powershelland press Enter. A PowerShell window opens in that folder. - Preview the change by adding
-WhatIf:Get-ChildItem -File -Filter 'IMG_*' | Rename-Item -NewName { $_.Name -replace '^IMG_','' } -WhatIf - Read the list of "What if: Performing the operation Rename File" lines. Check a few old and new names.
- Run the same command without
-WhatIfto rename for real. - Check the folder. If a file reported an error, read the message before trying again.
The script block in braces runs once per file. $_.Name is the current name, and -replace returns the new one. The -Filter 'IMG_*' part passes only files that start with the prefix. Without it, files that do not match get their own name back, and PowerShell may print a harmless error that the source and destination paths must be different.
Patterns for common prefixes and suffixes
| Remove | -replace pattern | Example |
|---|---|---|
| A fixed prefix | '^IMG_','' | IMG_0001.jpg → 0001.jpg |
| A date prefix | '^\d{8}_','' | 20240105_scan.pdf → scan.pdf |
| A track number | '^\d{1,3}(?:\s*-\s*|\.\s+)','' | 01 - Song.mp3 → Song.mp3 |
| A suffix before the extension | '_final(?=\.[^.]+$)','' | report_final.docx → report.docx |
| Copy markers | '(?: - Copy)?(?: \(\d+\))?(?=\.[^.]+$)','' | photo - Copy (2).jpg → photo.jpg |
| Any first N characters (here 4) | '^.{4}','' | ABC_notes.txt → notes.txt |
The lookahead (?=\.[^.]+$) means "followed by the extension at the end of the name". It ties the suffix to the position just before the last dot, so a_final_final.txt loses only the last _final, and a name like notes.final.txt is left alone. If you prefer, work on the base name and add the extension back: { ($_.BaseName -replace '_final$','') + $_.Extension }.
The track number pattern is deliberately strict. A looser ^\d+\s*[-.]\s* would also chop the year off a name like 2024-01-05 Report.pdf. When a pattern could plausibly hit names it should not, run it with -WhatIf and read every line.
Traps to watch for
Case-insensitive matching
-replace ignores case, so '^IMG_' also removes img_ and Img_. That is usually what you want with file names. If not, use -creplace for a case-sensitive match. The case-sensitive find and replace guide covers the difference.
Special characters in the prefix
The pattern is a regex. A prefix like [DRAFT] or v1.0- contains characters with special meanings. Escape them ('^\[DRAFT\] ', '^v1\.0-') or let PowerShell do it: $_.Name -replace ('^' + [regex]::Escape('[DRAFT] ')),''.
Name collisions
If IMG_0001.jpg and 0001.jpg both exist, removing the prefix would create a duplicate. Rename-Item refuses with an error that the file already exists, and moves on to the next file. Read any red error text, then handle those files by hand.
Files picked up twice
Because Get-ChildItem streams results while Rename-Item works, a renamed file can occasionally be listed again and renamed a second time. Wrapping the first command in parentheses, (Get-ChildItem -File -Filter 'IMG_*') | Rename-Item ..., collects the full list before any rename starts.
Empty names
A file called IMG_.jpg would become .jpg. Windows allows this, but it is easy to miss. A -WhatIf run shows it.
Square brackets in existing names
PowerShell treats [ and ] in paths as wildcards. Piping from Get-ChildItem, as above, avoids most problems, because the file object is passed directly. If you type a path by hand, use -LiteralPath.
Sub-folders and folder names
To include files in sub-folders, add -Recurse: Get-ChildItem -File -Recurse | Rename-Item -NewName { $_.Name -replace '^IMG_','' }. Keep -File so folders are not renamed while PowerShell is still walking through them, which can cause errors.
To rename folders too, do it as a separate step afterwards with -Directory, deepest first so parent paths stay valid while children are renamed:
Get-ChildItem -Directory -Recurse | Sort-Object { $_.FullName.Length } -Descending | Rename-Item -NewName { $_.Name -replace '^old_','' }
Command Prompt and File Explorer
The classic ren command supports wildcards, but it has no simple way to delete a fixed piece of text from the start of many names. Use PowerShell instead; it is installed on every supported version of Windows.
File Explorer's multi-rename (select files, F2, type a name) produces names like Holiday (1).jpg, Holiday (2).jpg. It is useful for giving files a common name, not for editing part of each name.
When other files refer to the renamed files
Renaming is the easy half if the files are web pages, images used by pages, scripts or documents linked from a help system. Every reference to IMG_0001.jpg also needs to become 0001.jpg, or links break. You have two options:
- Rename with PowerShell, then run a separate find and replace on the content, for example find
IMG_(?=\d{4}\.jpg)and replace with nothing in your .html and .css files. - Do both in one run with a tool that changes file names and contents together.
Bulk Replace can replace text in file and folder names in the same run as the file contents, or on its own. You see the old and new names in the preview before anything changes, and the run is backed up, so if a rename breaks something, one click restores the original names. Bulk Replace also writes a timestamped report of every change, which is handy when someone later asks what 0001.jpg used to be called. For general renaming beyond prefixes and suffixes, see replacing a word or characters in many file names.
Quick reference
- Prefix:
Get-ChildItem -File | Rename-Item -NewName { $_.Name -replace '^IMG_','' } - Suffix before extension:
$_.Name -replace '_final(?=\.[^.]+$)','' - Preview first: add
-WhatIf - Case-sensitive: use
-creplace - Include sub-folders: add
-Recurse, keep-File
Frequently asked questions
What PowerShell command removes a prefix from file names?
Get-ChildItem -File | Rename-Item -NewName { $_.Name -replace '^IMG_','' } removes IMG_ from the start of every file name in the current folder.
Why use ^ when removing a prefix?
The ^ anchor means the match must be at the start of the name, so IMG_ in the middle of a name is left alone.
What happens if two files end up with the same name?
Rename-Item fails for that file with an error that the file already exists. Check for collisions in a preview before renaming.
