0

I am trying to automate converting some old wav files to MP3 to free up storage using LAME encoder. Unfortunately, I am not having much sucess. I am using the following command:

forfiles /p "c:\wavfiles" /s /m *.wav /c "cmd /c c:\lame\lame.exe -q5 @path" This works, however it outputs the files into the same folder as the wav files. This makes it necessary to then move the files in a different process. There has to be a better way. 

Ideally, I would like to output the MP3 files to a different drive using the same folder structure using a single batch file.

I thought about using:

forfiles /p "c:\wavfiles\" /s /m *.wav /c ^&cmd /c C:\lame\lame.exe -q5 @path" &robocopy C:\wavfiles\ E:\converted *.mp3 /create /s /mov

However this does not seem to work, and seems rather inefficient.

I also thought about perhaps using the @relpath variable to copy the folder structure, so that I could try something like this:

forfiles /p "c:\wavfiles" /s /m *.wav /c "cmd /c c:\lame\lame.exe -q5 E:\@relpath" 

However I'm not sure how to do this. Any assistance would be appreciated. Thank you.

Squashman
  • 13,649
  • 5
  • 27
  • 36
Louis M
  • 11
  • 3
  • 1
    The syntax for for lame is pretty straight forward. `lame [options] inputfile [outputfile]`. You are not specifying an output file in any of your code examples. Regardless of that, you do not need to use `FORFILES` for this. You can use a standard `FOR` command. The only reason to use `FORFILES` would be to use the /D option. Using `FORFILES` creates a lot of overhead because you are opening a new cmd.exe session for every file you are processing. A simple for command: `FOR %%G in ("C:\wavefiles\*.wav") do c:\lame\lame.exe -q5 "%%G" "C:\MP3Files\%%~nG.mp3"` – Squashman Mar 16 '21 at 23:57
  • 1
    Open up a command prompt and type: `FOR /?` to read the syntax. You will probably want to use the `/R` option and if you are going to another drive and folder structure you will probably want to use the `md` command to make the folder structure on the other drive before running the `lame` command. You can do that easily with the `FOR` command modifiers. `md "E:%~pG"`. – Squashman Mar 17 '21 at 00:07
  • Hi Squashman. Thank you for the prompt reply. That was very helpful. Forgive me if I'm being a pest, but I am unable to test this presently. Would FOR %%G in ("C:\wavefiles\*.wav") do md "E:%~pG" c:\lame\lame.exe -q5... be correct? It seems as though this would create a new directory for each file, or at least attempt to. I thought about making the directory first, however I'm unsure about how to obtain and pass the original path to recreate it in the output folder. – Louis M Mar 17 '21 at 00:53
  • Yes. It will "attempt" to create the directory. If it already exists, it will throw an error message but will not crash the script. You can suppress the error message by redirecting to standard error to NUL. `md "C:\somefolder" 2>nul`. Or if you want to be super anal you may have noticed the `EXIST` option that you can use with the `IF` command. `IF NOT EXIST C:\somefolder\" md "C:\somefolder"` – Squashman Mar 17 '21 at 02:16

0 Answers0