Um9vdAo
Um9vdAo

Reputation: 63

Why does this REN command return "The syntax of the command is incorrect"?

I have some files in a folder like:

  1. Happysong.m4a.mp3
  2. Sad song ft. H.E.R.m4a.mp3

I want to rename these to:

  1. Happysong.mp3
  2. Sad song ft. H.E.R.mp3

Here is my code for test.bat file which is placed in the same folder:

for /f "delims=" %%a in ('dir  /b /a-d *.m4a.mp3') do (
  set "oldName=%%~a"
  set "newName=%oldName:.m4a=%"
  ren %%a "%newName%"
)

It returns The syntax of the command is incorrect.
I've tried:

for /f "delims=" %%a in ('dir  /b /a-d *.m4a.mp3') do (
  set "oldName=%%~a"
  set "newName=%oldName:.m4a=%"
  ren %%a %newName%
)

which returns ft. was unexpected at this time.
What am I doing wrong here?

Upvotes: 0

Views: 1253

Answers (1)

Compo
Compo

Reputation: 38613

You could probably do it like this from :

For %G In (*.m4a.mp3) Do @For %H In ("%~nG") Do @Ren "%G" "%~nH%~xG"

Or like this from a :

@For %%G In (*.m4a.mp3) Do @For %%H In ("%%~nG") Do @Ren "%%G" "%%~nH%%~xG"

Upvotes: 2

Related Questions