computing
  • 26

Solved Replace dots with spaces with .bat file

  • 26

 

Hello!

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

Example file
Monkeys.Cant.Sing.mp3

To
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”
)

 

Share

1 Answer

  1. 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.

    • 0