How to Rename Multiple Files at Once in Windows

Abstract: Batch rename multiple files in Windows using the cmd.exe for loop to add prefixes, modify suffixes, or change extensions without third-party software.

Created: 2026-08-17 by
Use the cmd.exe for loop command to rename multiple files simultaneously in Windows. This method allows you to batch process files by modifying prefixes, suffixes, or extensions without opening third-party software. It is particularly useful for organizing large directories of images, documents, or data logs efficiently.

Preparing Your Command Prompt

To begin renaming files via the command line, you must first navigate to the directory containing those files. Open a new Command Prompt window by pressing Win + R, typing cmd, and hitting Enter. Once the black terminal window appears, use the cd (change directory) command followed by the path to your target folder. For example, if your photos are in a subfolder named "Vacation" on your Desktop, you would type cd C:\Users\YourName\Desktop\Vacation. Pressing Enter will move your current working directory to that location. You can verify you are in the correct spot by running dir, which lists all files currently present. It is critical to ensure that the files you intend to rename are not currently open in other applications. Closing programs like Microsoft Word, Photoshop, or media players prevents access denied errors during the batch operation. Additionally, consider creating a backup copy of your files before running any bulk rename scripts. While the commands below are generally safe, a syntax error could result in unintended file modifications or overwrites. Having a backup ensures you can restore original names if something goes wrong.

Renaming Files Using a Prefix

One of the most common tasks is adding a consistent prefix to many files. The for loop iterates through each file matching a specific pattern and executes the ren (rename) command. To add the text "Old_" to the beginning of every JPEG image in the current folder, use the following structure:
for %f in (*.jpg) do ren "%f" "Old_%f"
In this command, %f represents a temporary variable that holds the name of each file as the loop processes it. The *.jpg part specifies that only files ending with the .jpg extension should be targeted. The do keyword separates the selection criteria from the action. The ren command takes two arguments: the source filename ("%f") and the new filename ("Old_%f"). By wrapping variables in quotes, you protect filenames that contain spaces from causing syntax errors. If you are using a batch script (.bat file) rather than typing directly into the interactive command prompt, you must double the percent signs. In a script, the command becomes for %%f in (*.jpg) do ren "%%f" "Old_%%f". This distinction is vital; using single percent signs in a batch file will cause the script to fail because the command interpreter interprets them differently in non-interactive contexts.

Modifying File Extensions

Sometimes the goal is not to change the visible name but to update the file extension itself. This is often necessary when converting file formats or correcting mistakes made by other applications. Suppose you have several files incorrectly saved as .txt that are actually CSV data. You can change their extensions using a similar loop:
for %f in (*.txt) do ren "%f" "%~nf.csv"
Here, %~nf is a modifier that extracts only the name portion of the file, excluding the original extension. This effectively strips the old extension and appends the new one. This technique is safer than manually typing new names because it preserves the original base name automatically. It works for any extension pair, allowing you to switch between .doc and .docx, or .png and .jpeg, provided the underlying file content remains compatible with the new format. For more complex scenarios involving multiple folders, you might need to traverse subdirectories. Adding the /r flag to the for loop enables recursive searching. The command for /r %f in (*.log) do echo %f will list all log files in the current directory and all nested subfolders. Combining this with the rename function allows you to clean up entire project structures at once, ensuring consistency across all levels of your directory tree.

Handling Spaces and Special Characters

Windows handles filenames with spaces poorly in older scripting environments. Always enclose your variables in double quotes to ensure the command processor treats the entire string as a single argument. Without quotes, a file named "My Document.pdf" might be interpreted as two separate arguments: "My" and "Document.pdf", leading to errors. The examples provided above include these protective quotes around %f and the target names. If you encounter issues where some files fail to rename while others succeed, check for permission restrictions or active file locks. Running the Command Prompt as an Administrator can resolve permission-denied errors for files located in protected system directories. However, for user documents in standard folders, administrative rights are usually unnecessary. If a specific file refuses to rename, close any associated applications and try again.

Verifying the Results

After executing your rename command, always verify the changes by listing the directory contents again with the dir command. Visually scan the output to ensure the new naming convention was applied correctly to all intended files. If you notice anomalies, such as missing extensions or incorrect prefixes, you can reverse the process by running a similar loop that swaps the old and new patterns back to the original state. Being able to quickly undo bulk operations is a key advantage of using scripted renaming over manual graphical interface methods.

Frequently Asked Questions

Can I rename files using PowerShell instead of CMD?

Yes, PowerShell offers more robust object-oriented handling for file manipulation. You can use the Rename-Item cmdlet combined with Get-ChildItem to achieve similar results with greater flexibility for complex naming logic.

What happens if I accidentally overwrite a file during renaming?

If the new name already exists, Windows will prompt you to confirm whether you want to replace the existing file. If you proceed, the original file with the duplicate name will be permanently deleted and replaced by the renamed file.

Does this method work on network drives?

Yes, the ren command works on mapped network drives just as it does on local hard drives. However, performance may be slower depending on network latency, so batch operations on large numbers of files might take longer to complete.

How do I remove a prefix from multiple files?

To remove a prefix, you can use a substring extraction or a regular expression if using PowerShell. In CMD, it is easier to rename the files to a generic name first, then apply a new prefix, as direct subtraction of characters is not natively supported in basic ren syntax.

Why did my batch script fail with a syntax error?

Batch scripts require double percent signs (%%) for variables inside loops, whereas interactive CMD windows use single percent signs (%). Using the wrong syntax in a .bat file is the most common cause of immediate failure.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More