Rename multiple files in a folder, add a prefix (Windows)
Categories:
Batch Rename Files: Adding a Prefix in Windows

Learn how to efficiently add a prefix to multiple filenames in a Windows folder using PowerShell, a powerful scripting tool for system administration.
Renaming a single file is straightforward, but when you need to add a consistent prefix to dozens or even hundreds of files, manual renaming becomes tedious and error-prone. This article will guide you through using PowerShell, a command-line shell and scripting language built into Windows, to quickly and effectively batch rename files by adding a prefix. This method is invaluable for organizing documents, photos, or any collection of files that require a standardized naming convention.
Understanding the PowerShell Rename-Item
Cmdlet
PowerShell's Rename-Item
cmdlet is the core command we'll use for this task. It allows you to change the name of an item (like a file or folder). When combined with other cmdlets, such as Get-ChildItem
(to list files) and a ForEach-Object
loop, it becomes a powerful tool for bulk operations. The key to adding a prefix is constructing a new filename that includes both your desired prefix and the original filename.
flowchart TD A[Start] --> B["Get-ChildItem (List Files)"] B --> C{"For Each File"} C --> D["Construct New Name (Prefix + Original Name)"] D --> E["Rename-Item (Apply New Name)"] E --> C C --> F[End]
Flowchart of the batch renaming process using PowerShell.
Preparing Your Environment and Files
Before you begin, it's crucial to prepare your files and understand the process. Always work on a copy of your files first, especially when performing batch operations, to prevent accidental data loss. Identify the target folder and the specific prefix you want to add. PowerShell commands are case-insensitive for cmdlets but often case-sensitive for file paths and names, so pay attention to your input.
Step-by-Step Guide to Adding a Prefix
Follow these steps to add a prefix to all files within a specified folder. We'll use a simple PowerShell script that you can adapt to your needs.
1. Open PowerShell
Press Win + X
and select 'Windows PowerShell' or 'Windows PowerShell (Admin)' from the menu. You can also search for 'PowerShell' in the Start menu.
2. Navigate to the Target Directory
Use the cd
command to change your current directory to the folder containing the files you want to rename. For example, if your files are in C:\Users\YourUser\Documents\MyFiles
, type: cd C:\Users\YourUser\Documents\MyFiles
3. Execute the Renaming Command
Once in the correct directory, use the following PowerShell command. Replace 'MyPrefix_'
with your desired prefix and ensure the *.*
matches the file types you want to target (e.g., *.txt
for text files, *.*
for all files).
Get-ChildItem -Path . -File | ForEach-Object {
$newName = "MyPrefix_" + $_.Name
Rename-Item -Path $_.FullName -NewName $newName
}
4. Verify the Renaming
After running the command, check the folder to ensure all files have been renamed correctly with the new prefix. You can use Get-ChildItem
again in PowerShell or simply open File Explorer.
Get-ChildItem -Path "C:\Path\To\Your\Files" -File | ForEach-Object {
$prefix = "ProjectA_"
$newName = $prefix + $_.Name
Rename-Item -Path $_.FullName -NewName $newName -WhatIf
}
# To execute the rename, remove '-WhatIf'
# Get-ChildItem -Path "C:\Path\To\Your\Files" -File | ForEach-Object {
# $prefix = "ProjectA_"
# $newName = $prefix + $_.Name
# Rename-Item -Path $_.FullName -NewName $newName
# }
PowerShell script to add a prefix to all files in a specified directory. The -WhatIf
parameter is used for a dry run.
-WhatIf
parameter is extremely useful for testing your PowerShell commands without actually making changes. It shows you what would happen if you ran the command. Always use it for batch operations before committing to the changes.