Handling lots of files can be really boring, especially if you need to change their names to follow a certain pattern. This could be organizing your photos, backup files, or any bunch of documents. Good news for Windows 11 and Windows 10 users, there’s a built-in tool called PowerShell that makes it super easy to add beginnings (prefixes) or endings (suffixes) to the names of lots of files at once. We’re going to walk you through how to use PowerShell for this task. It’s basically just a few commands away.
Also see: How to Batch Rename Files in Windows 11
Page Contents
Adding a suffix to all files in a folder using PowerShell
PowerShell is a tool from Microsoft that helps you automate tasks and script things out, and it’s great for managing files. With a few simple commands, you can rename lots of files in a folder, like adding a suffix to all of them in one go or more places.
How it works:
The trick to adding a suffix using PowerShell is all about two commands: Get-ChildItem
and Rename-Item
.
Get-ChildItem
lets you see all the stuff (like files and folders) in a certain spot. It’s pretty much like thels
command on Unix ordir
on Windows Command Prompt.Rename-Item
is for changing the name of a file or folder.
Putting these two together lets you grab all the files in a place and change their names to add the suffix you want.
Pro tip: How to Move All Files from Subfolders to Main Folder in Windows 10/11
Steps to add a suffix to multiple filenames:
- Open PowerShell:
- Right-click the Start menu.
- Select “Windows PowerShell (Admin)”. You might need admin rights for some places or system spots to change file names.
- Navigate to the Folder:
- Type
cd
and then the path of your folder. Like this:cd "C:\Users\YourUsername\Documents\YourFolder"
- Type
- Add Suffix:
- Type this command, but change ‘_MySuffix’ to whatever you want to add:
Get-ChildItem | Rename-Item -NewName { $_.BaseName + '_MySuffix' + $_.Extension }
Here’s what this command does:Get-ChildItem
: Gets everything in the folder.Rename-Item -NewName
: Changes the name of each thing we found.- The magic part:
{ $_.BaseName + '_MySuffix' + $_.Extension }
takes the original file name, adds your suffix, and puts the file extension back on.
- Type this command, but change ‘_MySuffix’ to whatever you want to add:
Example:
Imagine you have these files:
landscape.jpg portrait.jpg notes.txt
After you run the PowerShell command with ‘_Edited’, your files will be named:
landscape_Edited.jpg portrait_Edited.jpg notes_Edited.txt
And just like that, you’ve renamed all your files in a folder using PowerShell. It’s quick and handy, especially when you’ve got a ton of files to deal with.
Related concern: Can I Manually Sort Files in a Folder in Windows 11?
Adding a prefix to all files in a folder using PowerShell
Adding prefixes to file names with PowerShell is just as easy as adding suffixes. It’s basically the same steps but in reverse, sticking your text at the start of the file names instead.
How it works:
To add a prefix, you slightly change how you use the same two commands.
Steps to add a prefix to multiple filenames:
- Open PowerShell:
- Right-click the Start menu.
- Pick “Windows PowerShell (Admin)”. You might need admin rights for some folders or system areas to change file names.
- Navigate to the Folder:
- Type
cd
and the path to your folder, like so:cd "C:\Users\YourUsername\Documents\YourFolder"
- Type
- Add Prefix:
- Type this command, but swap ‘MyPrefix_’ with the prefix you want:
Get-ChildItem | Rename-Item -NewName { 'MyPrefix_' + $_.Name }
This breaks down to:Get-ChildItem
: Grabs everything in the folder.Rename-Item -NewName
: Renames what we found.- The magic:
{ 'MyPrefix_' + $_.Name }
sticks ‘MyPrefix_’ in front of each file name.
- Type this command, but swap ‘MyPrefix_’ with the prefix you want:
Example:
Let’s say your folder has:
photo1.jpg photo2.jpg document.txt
With the PowerShell command and ‘Vacation_’ as the prefix, they’d change to:
Vacation_photo1.jpg Vacation_photo2.jpg Vacation_document.txt
PowerShell makes renaming files super straightforward, whether you’re adding prefixes or suffixes. It’s a big help in keeping things organized, especially with lots of files.
Linked issue: Rename Folder: “Can’t find the specified file” in Windows 11
Tips for using PowerShell for file renaming
Now that you know how to add prefixes and suffixes with PowerShell, here are some extra tips to make things go smoothly.
Working with specific file types
If you only want to change the names of a certain type of file, like just .jpg
files, you can tweak the Get-ChildItem
command like this:
Get-ChildItem -Filter *.jpg | Rename-Item -NewName { 'MyPrefix_' + $_.Name }
Conditional renaming
Maybe you only want to rename files that were changed in the last week. You can do that with this command:
Get-ChildItem | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) } | Rename-Item -NewName { 'Recent_' + $_.Name }
About undoing changes
One thing to remember is that PowerShell doesn’t have an “undo” button. So, be careful:
- Always back up your stuff before running scripts. If something goes wrong, you can go back to how things were.
- Try your script on a few files first to make sure it does what you want.
- If you accidentally rename things wrong, you might be able to write another script to fix it. But it’s tricky, so better safe than sorry—backup!
Avoid overwriting existing files
Make sure your new names don’t clash with ones you already have. If two files get the same name, one will disappear.
Recursive renaming
If you need to change names in a folder and its subfolders, use the -Recurse
option with Get-ChildItem
:
Get-ChildItem -Recurse | Rename-Item -NewName { 'MyPrefix_' + $_.Name }
Be extra careful with -Recurse
since it affects lots of files. Always double-check you’re in the right spot.
Common issues when adding prefix or suffix to filenames with PowerShell
Sometimes things don’t go as planned. Here’s how to deal with some common problems:
Permission denied error
If you see “Access to the path is denied”, it’s usually about permissions.
Solution:
- Make sure no program is using the files.
- Check if the file is ‘Read-Only’ in its properties.
- Try running PowerShell as an Administrator by right-clicking its icon and choosing “Run as administrator”.
Invalid characters in filenames
Windows doesn’t like certain characters in filenames. If your prefix or suffix has them, you’ll run into trouble.
Solution:
- Check your prefix or suffix for these bad characters and change them if needed.
File name too long error
Windows has a limit on how long file names can be. If your new name is too long, it won’t work.
Solution:
- Try shorter prefixes or suffixes.
- Move your files to a place with a shorter path before renaming.
Files not being renamed
If your files aren’t changing names and you’re not seeing errors, maybe the script isn’t looking in the right place.
Solution:
- Double-check you’re in the right folder with the
cd
command. - If you’re filtering with
Get-ChildItem
, make sure it’s set up right.
Renamed files have double extensions
If your files end up with names like filename.jpg.jpg
, the script is adding the extension twice.
Solution:
- Make sure your script uses
$_.BaseName
for the file name without the extension and then adds$_.Extension
just once.
Final thoughts
Changing file names one by one is a drag, especially with lots of them. PowerShell is a built-in tool in Windows that can do this fast without needing anything else. It’s a lifesaver when you have to rename many files, like adding prefixes or suffixes. Give PowerShell a try next time, and you’ll see how simple it can be.