Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

windows - 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?

question from:https://stackoverflow.com/questions/65859003/why-does-this-ren-command-return-the-syntax-of-the-command-is-incorrect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...