Rename multiple files in a folder, add a prefix (Windows)
The problem with the two Powershell answers here is that the prefix can end up being duplicated since the script will potentially run over the file both before and after it has been renamed, depending on the directory being resorted as the renaming process runs. To get around this, simply use the -Exclude
option:
Get-ChildItem -Exclude "house chores-*" | rename-item -NewName { "house chores-" + $_.Name }
This will prevent the process from renaming any one file more than once.
Option 1: Using Windows PowerShell
Open the windows menu. Type: "PowerShell" and open the 'Windows PowerShell' command window.
Goto folder with desired files: e.g. cd "C:\house chores" Notice: address must incorporate quotes "" if there are spaces involved.
You can use 'dir' to see all the files in the folder. Using '|' will pipeline the output of 'dir' for the command that follows.
Notes: 'dir' is an alias of 'Get-ChildItem'. See: wiki: cmdlets. One can provide further functionality. e.g. 'dir -recurse' outputs all the files, folders and sub-folders.
What if I only want a range of files?
Instead of 'dir |' I can use:
dir | where-object -filterscript {($_.Name -ge 'DSC_20') -and ($_.Name -le 'DSC_31')} |
For batch-renaming with the directory name as a prefix:
dir | Rename-Item -NewName {$_.Directory.Name + " - " + $_.Name}
Option 2: Using Command Prompt
In the folder press shift+right-click : select 'open command-window here'
for %a in (*.*) do ren "%a" "prefix - %a"
If there are a lot of files, it might be good to add an '@echo off' command before this and an 'echo on' command at the end.