Rename Multiple Folders in Windows Directory
This guide shows how to rename multiple folders in a Windows directory using a batch script.
Prerequisites
- A Windows system
- Command Prompt with administrative privileges
Instructions
- Replace `C:\YourDirectory` with the path to the directory containing the folders you want to rename.
- Save the following script as a `.bat` file (e.g., `rename_folders.bat`).
- Run the script in the Command Prompt with administrative privileges.
Script
@echo off
setlocal enabledelayedexpansion
set "dir=C:\YourDirectory"
set "prefix=Name, Surname"
set "suffix=Name"
for /d %%D in ("%dir%\*") do (
set "folder=%%D"
set "name=%%~NxD"
set "name=!name:*!, !name:*%%%!"
set "name=!name:%prefix%=%suffix%!"
ren "%%D" "!name!"
)
Notes
- This script will not work if folder names contain spaces in the `Surname` or `Name` parts. To handle this case, you can modify the script to use double quotes around the folder names when setting the `name` variable.