Replacing Characters in filename

A very quick snippet pasal nak replace character dan append string dalam filename menggunakan batch script.

Appending string

@echo off
for %%a in (*.png) do ren "%%a" "ic_%%a"

Where ic_ in line 2 is the string we want to append. %%a is just a variable that holds the original filename.

Replacing character

@echo off

Setlocal enabledelayedexpansion

Set "Pattern=-"
Set "Replace=_"

For %%# in ("*.png") Do (
    Set "File=%%~nx#"
    Ren "%%#" "!File:%Pattern%=%Replace%!"

This script replaces - with _. See Pattern and Replace variables.

Save this script as .bat in a folder you want to process its containing file, run it.

Show Comments

Get the latest posts delivered right to your inbox.