rename multiple files windows 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: batch rename file
REM # | EXAMPLE (changes the "ChangeMyName.txt" file's name to "NameChanged.csv")
rename "C:/Users/JacquesK/ChangeMyName.txt" "NameChanged.csv"
REM # | SYNTAX
REM # | rename "<file-to-change-the-name-of>" "<new-file-name>"
Example 3: rename all files in a folder command line
for file in Picture*.jpg
do
mv "$file" "vacation-$file"
done
Example 4: batch rename files
REM # (1) Rename files (not folders) in the current folder only
REM # (2) Rename files (not folders) in the current folder and its subfolders
REM # | EXAMPLE (1)
REM # | ---------------------------------------------------------------
REM # | Replace ")" with "_" within the filenames in the current folder only
@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!%%
if NOT !InitName!==!NewName! (
echo rename "!InitName!" "!NewName!"
rename "!InitName!" "!NewName!"
)
)
@echo on
REM # | EXAMPLE (2)
REM # | ---------------------------------------------------------------
REM # | Replace ")" with "_" within the filenames in the current folder and all its subfolders
@echo off
setlocal EnableDelayedExpansion
set "pattern_to_replace= "
set "replace_text=_"
for /R "%cd%" %%N in ("*") do (
set "InitName=%%~nN%%~xN"
call set NewName=%%InitName:!pattern_to_replace!=!replace_text!%%
if NOT %%N==%%~dN%%~pN!NewName! (
echo rename "%%~dN%%~pN!InitName!" "!NewName!"
rename "%%~dN%%~pN!InitName!" "!NewName!"
)
)
@echo on
REM # | ---------------------------------------------------------------