Here in the post, We’ll develop a Mass Rename Tool using Windows Batch Programming, a powerful but often overlooked scripting method built into Windows which will rename multiple files.
Building a Mass Rename Tool Using Batch Programming
Getting Started
Whether you’re a photographer or a developer, you might need to organize thousands of files to stay productive. You may want to rename your files quickly and efficiently. Renaming multiple files manually can be a tedious and time-consuming task.
Building a Mass Rename Tool can save you hours of tedious manual work. Below are the details on how to create a bulk rename tool(Mass Rename Tool) using batch programming
The bulk rename utility(Mass Rename Tool) will allows users to rename multiple files in a folder by applying patterns like:- Adding Preffixes or Suffixes
- Replacing specific parts of filenames
- Sequential numbering
Prerequisites
Before we start, make sure you have:- A Windows machine
- Basic knowledge of the Command Prompt
- A text editor (like Notepad, VS Code, or Notepad++)
Open Notepad and save the file with a mass_rename_tool.bat
extension, then copy the blow batch scrips into the .bat
file and save it again.
@echo off
setlocal enabledelayedexpansion
color a
:: Prompt for folder
set /p folder="Enter the folder path: "
cd /d "%folder%"
:: Prompt for rename mode
echo.
echo Choose rename mode:
echo 1. Add prefix
echo 2. Add suffix
echo 3. Replace text
echo 4. Sequential numbering
set /p mode="Enter mode number: "
:: Handle modes
if "%mode%"=="1" goto :addPrefix
if "%mode%"=="2" goto :addSuffix
if "%mode%"=="3" goto :replaceText
if "%mode%"=="4" goto :sequential
:addPrefix
set /p prefix="Enter prefix: "
for %%f in (*.*) do (
ren "%%f" "%prefix%%%~nxf"
)
echo Done.
:addSuffix
set /p suffix="Enter suffix (before extension): "
for %%f in (*.*) do (
set "name=%%~nf"
set "ext=%%~xf"
ren "%%f" "!name!%suffix%!ext!"
)
echo Done.
:replaceText
set /p search="Enter text to replace: "
set /p replace="Enter replacement text: "
for %%f in (*.*) do (
set "old=%%~nxf"
set "new=!old:%search%=%replace%!"
if not "!old!"=="!new!" (
ren "%%f" "!new!"
)
)
echo Done.
:sequential
set /p base="Enter base name: "
set /a counter=1
for %%f in (*.*) do (
set "ext=%%~xf"
set "newname=%base%!counter!%%~xf"
ren "%%f" "!newname!"
set /a counter+=1
)
echo Done.
goto :eof
How Above Batch Programming Scripts Work
Based on the pattern, the batch scripts are divided into four sections, with each section handling a specific renaming task.
Batch Script: Add Prefix Mode :addPrefix
set /p prefix="Enter prefix: "
for %%f in (*.*) do (
ren "%%f" "%prefix%%%~nxf"
)
echo Done.
goto :eof
Add Suffix Mode
:addSuffix
set /p suffix="Enter suffix (before extension): "
for %%f in (*.*) do (
set "name=%%~nf"
set "ext=%%~xf"
ren "%%f" "!name!%suffix%!ext!"
)
echo Done.
goto :eof
Replace Text Mode
:replaceText
set /p search="Enter text to replace: "
set /p replace="Enter replacement text: "
for %%f in (*.*) do (
set "old=%%~nxf"
set "new=!old:%search%=%replace%!"
if not "!old!"=="!new!" (
ren "%%f" "!new!"
)
)
echo Done.
goto :eof
Sequential Numbering Mode
set /a counter=1
for %%f in (*.*) do (
set "ext=%%~xf"
set "newname=%base%!counter!%%~xf"
ren "%%f" "!newname!"
set /a counter+=1
)
echo Done.
goto :eof
Summary
Batch scripting is still a valid choice for quick file system operations, especially when GUI tools aren’t available and it is essential for managing large sets of digital files. With just a few lines of code, you can create a Mass Rename Tool that saves both time and effort.
Thanks