2

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.

monstro
  • 6,254
  • 10
  • 65
  • 111
  • 1
    What does "it's not working" mean exactly? We can't see your screen or read your mind from where we are, so when you say "it's not working" you need to describe to us how "it's not working". Until you do, the phrase is meaningless to everyone but you. If you want help here, be **specific** about the problem. Otherwise, you're wasting your (and our) time. Thanks. – Ken White Jan 20 '13 at 17:51
  • What do you mean by its not working? You should provide more details, so that users can provide their inputs. – CuriousMind Jan 20 '13 at 17:55
  • I have updated the question with more info. Thanks. – monstro Jan 20 '13 at 18:18
  • Provided. Any suggestions? – monstro Jan 21 '13 at 04:30
  • Add an `echo "%%f"` command right before you delete the original file. This should give you a hint of the file location. – Andreas Jan 22 '13 at 14:57

1 Answers1

3

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
monstro
  • 6,254
  • 10
  • 65
  • 111
  • I just needed the loop to look like: ` "c:\Program Files (x86)\Lame For Audacity\lame.exe" -h -V 0 "%%f" "%%~nf.mp3" ` for my purposes, so thanks. I'm rusty on Batch. (also adjusted the filters to *.wav) – The Nate Apr 24 '20 at 22:43