Solved Replace dots with spaces with .bat file

July 1, 2012 at 02:39:07
Specs: Windows 7

I want to replace the dots in filenames with spaces. With the aid of a bat file

Example file

Monkeys Cant Sing.mp3

I found this code that replaces dots with _ characters. I thought that I was able to modify the code to suit my needs, but I could not. I did not understand commands in the file. :-$

@ echo off
setlocal enabledelayedexpansion
for%% j in (*. *) do (
set filename =%% ~ nj
set filename =! filename:. = _!
set filename =! filename: = _!
if not! "filename" == "%% ~ nj" ren "%% j" ": filename:%% ~ xj"

See More: Replace dots with spaces with .bat file

Report •

July 1, 2012 at 04:38:23
It may be simpler in the long run to just use a program designed to do the work for you:

"Channeling the spirit of jboy..."

Report •

July 1, 2012 at 11:31:27
✔ Best Answer
set filename =%%~nj
set ext=%%~xj
set filename=!filename:. = !
set filename=!filename!.!ext!
if not exist "!filename!" ren "%%j" " "!filename!"

not tested
I had no clue what that last line was trying to do, so I guessed it was testing that the new filename didn't already exist.

Report •

Related Solutions

Ask Question