Question

I need to get working properly a tiny Windows batch file (convert.cmd) that changes bitrate of all MP3 files in a specified folder. I need to pass 2 parameters to the batch file:

  • the path to the folder with MP3 files
  • bitrate I want to change them to.

I am using Lame.exe encoder. The lame.exe is in one place, convert.cmd can be in the same folder with lame.exe, but the folder with MP3 files can be anywhere. The original version (without parameters) was (and it's working fine if I place convert.cmd in the folder wit MP3 files):

@ECHO OFF
FOR %%f IN (*.mp3) DO (
    D:\Apps\Lame\lame.exe -h -b 128 "%%f" "%%f.temp"
    DEL "%%f"
    REN "%%f.temp" "%%f"
)
PAUSE

Instead of 128 I need to pass "%2" and it will be a second command-line parameter, the bitrate, and for MP3 files folder path I need to pass "%1". So, I got this, but it's not working.

@ECHO OFF
FOR %%f IN (%1\*.mp3) DO (
    D:\Apps\Lame\lame.exe -h -b %2 "%%f" "%%f.temp"
    DEL "%%f"
    REN "%%f.temp" "%%f"
)
PAUSE

How to make it work as described?

How can I ensure that my batch file convert existing files, and not creating new converted copies of them somewhere? Thanks a bunch ;) Cheers.

UPDATE

The location of convert.cmd is:

d:\Apps\Lame\convert.cmd, same folder with lame.exe

The location of MP3 files is:

d:\temp\xxx\

  • File1.mp3
  • File2.mp3

When I execute convert.cmd from the command line like this:

convert.cmd d:\temp\xxx\ 64

what I get in d:\temp\xxx\ is this:

  • File1.mp3.temp
  • File2.mp3.temp

Where did the converted files go?

Thanks.

Was it helpful?

Solution

Thanks, I have already figured out how to write this script.

If someone needs this type of conversion, here we go: 1 param - full path to the folder with mp3 files 2 param - bitrate to convert to

(remember, lame.exe does not preserve mp3 tags) p.s. who needs mp3 tags anyways ? :)

@ECHO OFF
ECHO.
ECHO BEGIN CONVERSION
ECHO.
CD %1
DIR *.mp3
ECHO -------------------------------------------------------------------------------
ECHO THESE MP3 FILES WILL BE CONVERTED TO BITRATE %2 KBPS
ECHO -------------------------------------------------------------------------------
PAUSE
FOR %%f IN (*.mp3) DO (
    ECHO -------------------------------------------------------------------------------
    ECHO CONVERTING: %%f
    ECHO -------------------------------------------------------------------------------
    D:\Apps\Lame\lame.exe -h -b %2 "%%f" "%%~nf.wav"
    DEL "%%f"
    REN "%%~nf.wav" "%%f"
)
ECHO.
ECHO END CONVERSION
ECHO.
PAUSE
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top