Skip to main content

Batch Renaming

· 3 min read
Amesim tutorial author

Three methods for batch renaming files, with Quicker being the ultimate solution

Recently, while writing some articles, I needed to ensure file and folder names didn't contain spaces due to specific requirements. Initially, I did this manually, but it became tedious, so I explored better methods.

1. My Familiar Approach: Batch Files

With large language models available, I didn't need to write code myself. I simply described my requirements:

1. Requirements Background

Create a batch file that replaces spaces in filenames with hyphens.

2. Detailed Requirements

Batch File Location: Name the batch file replace_spaces.bat and place it in the F:\Wilson\sim directory. This directory contains no spaces, avoiding path parsing issues.

Functionality: When executed, the batch file should replace spaces with hyphens in all filenames in the current working directory, excluding files and folders in subdirectories.

Execution Method: Run the batch file by entering its full path in PowerShell from any folder. The batch file will automatically process all filenames in the current PowerShell directory.

Special Case Handling: Consider special cases like filenames that already contain hyphens (these should remain unchanged, only spaces should be replaced). Also, ensure no operations on system or protected files to avoid rendering files unusable due to name changes.

Feedback Mechanism: Provide feedback during processing, such as displaying the filenames being processed and, upon completion, a summary of how many files were successfully processed or if any failures occurred.

3. Code Implementation

@echo off
setlocal enabledelayedexpansion

rem 遍历当前目录下的所有文件和文件夹
for /f "delims=" %%F in ('dir /b /a-d-h-s') do (
set "filename=%%F"
set "newname=!filename: =-!"
if not "!filename!"=="!newname!" (
echo Renaming "!filename!" to "!newname!"
ren "!filename!" "!newname!"
)
)

for /f "delims=" %%D in ('dir /b /ad-h-s') do (
set "dirname=%%D"
set "newdirname=!dirname: =-!"
if not "!dirname!"=="!newdirname!" (
echo Renaming "!dirname!" to "!newdirname!"
ren "!dirname!" "!newdirname!"
)
)

echo Process completed.
endlocal

After the AI generated the code, I opened PowerShell in the target folder and executed:

start-Process -FilePath "F:\Wilson\sim\replace_spaces.bat"

The result was perfect - all spaces in file and folder names were successfully replaced with hyphens.

2. Basic Use of the Efficiency Tool Quicker

Method 1 still required opening PowerShell and entering commands, which wasn't streamlined enough. So I turned this workflow into a one-click command in Quicker, making it much simpler to execute when needed.

3. Advanced Use of Quicker - The Ultimate Solution

While using Method 2, I discovered an even simpler approach in Quicker. I could select the files and folders to rename, click on EVER Rename, use find and replace to change spaces to hyphens, and click confirm. This one-click solution requires no programming or complex thinking. Furthermore, EVER Rename offers many more powerful naming features, making it the ultimate efficiency tool for renaming, highly recommended.

Quicker's capabilities are definitely worth exploring further.

image-20250504145050098

image-20250504145218882

Execution result:

image-20250504151154568