windows cmd rename multiple files code example
Example 1: cmd rename multiple files
# EXAMPLE: add "_zzz" to the name of each file found within the "G:\Deletable\" folder
for /d %F in ("G:\Deletable\*") do rename "%F" "%~nF_zzz%~xF"
# SYNTAX
# for <your-options> %F in ("<root-directory>\*") do rename "%F" "%~n#<your-text-to-add>%~xF"
Example 2: cmd rename multiple folders
# EXAMPLE: adds "_zzz" to every folder found within the "G:\Deletable\" folder
for /d %F in ("G:\Deletable\*") do rename "%F" "%~nF_zzz"
# SYNTAX
# for <your-options> %F in ("<root-directory>\*") do rename "%F" "%~nF<your-text-to-add>"
# NOTE: if you would like to replace an internal substring with text in a directory, use the following
# example: this replaces all the ")" characters with "_"
@echo off
setlocal EnableDelayedExpansion
set "pattern_to_replace=("
set "replace_text=_"
for %%N in ("*") do (
set "InitName=%%N"
call set NewName=%%InitName:!pattern_to_replace!=!replace_text!%%
rename "!InitName!" "!NewName!"
)
@echo on