Windows bat file for Foobar Replay Gain & MP3Tag

Greetings - I have been using a bat file that I found on-line for a long time to add replay gain using foobar2000 and then send the files to mp3tag. It used to automatically open mp3tag after foobar2k applied the replay gain, but that has stopped working.

Actually, the foobar2k replay gain stopped working after I upgraded, but I got that going again by downgrading back to the really old version that I was using - v1.3.13. However now, mp3tag doesn't open automatically after foobar2k is finished like it used to. I have no idea why as I am not a programmer.

Maybe someone here can help? I'm sure it's probably something trivial for someone that is familiar with stuff. I'd really appreciate it if someone could take a look and let me know how to fix this issue. Here is the bat file that I use on Win10.

@echo off
Echo Sending selected files to Foobar2000 to apply Album-level ReplayGain...
"%PROGRAMFILES(x86)%\foobar2000\foobar2000.exe" /context_command:"Replaygain/Scan selection as albums (by tags)" %*
if not %ERRORLEVEL%==0 goto :errorfoobar
Echo Sending direcotry to MP3Tag so you can apply the actions...
"%PROGRAMFILES(x86)%\Mp3tag\mp3tag.exe" /fp:%1
if not %ERRORLEVEL%==0 goto :errormp3tag

echo Foobar2000 exited abnormally, ending script

echo MP3Tag exited abnormally, ending script

the commands in the file are not too complicated.
So you could test them individually.
I would investigate first of all whether the path that is used to call MP3tag is still correct.
That is something that only you can check locally.

Copy & paste this program call into your windows file explorer adress bar.
If it does not show you the same adress automatically, this folder is not the matching one.
Then you have to manually find your local Mp3tag installation path where the mp3tag.exe is stored in.


And maybe you should enclose your %1 like this
to avoid problems with directories or filenames containing a space.

"%PROGRAMFILES(x86)%\Mp3tag\mp3tag.exe" /fp:"%1" will work OK if the file or directory has no spaces in its path.
But if there are spaces, %1 expands with double quotes automatically added around the path.

If the path of the directory is W:\path with spaces\album folder, the command will fail because "%1" becomes ""W:\path with spaces\album folder""

Maybe you will be interested in how batch parameters can be expanded:

1 Like

So you say, the official help about this topic is wrong?

OK @ryerman is right. If you use this command line in a batch file, you must not use the double quotes around the %1.

This is only necessary if you call the same command directly from a manually opened CMD window:

otherwise you get this errors:

Appreciate the responses! I should have said that I did try to figure this out by doing things like copying the individual commands into a cmd line, etc before posting and asking for help.

The path is ok. Mp3tag opens. This issue seems to be with the /fp:%1 part. I assume this means, open the current directory and that's the part that's not working? I tried enclosing the "%1" but that didn't work either. Here is the error I am getting


The weird thing is that this worked for years. Things just went wonky when I upgraded and then downgraded foobar2k. Very strange.

You should have a look at the content of the variable %1.
Just insert

echo %1

before "echo sending .."

I don't know how you call the batch file - I mean: where and how do you pass over the current folder name?
I would think that as soon as the path has space characters in it, you have to enclose the whole path string with quotation marks,

I call the batch file by right-clicking on a bunch of files and then from the context menu I select "Send to Apply Gain". I followed an on-line guide to set this up several years ago and now the guide is gone. Here is the ouput after adding

echo %1

before "echo sending..." as suggested


I can see no path or anythink like it being echoed.
So it looks like the batch file does not get the path.
You would now have to investigate how to modify the shell extension call.
(This, BTW, has nothing to do with MP3tag even though MP3tag happens to be called - this is just coincidental.)

Yes, I see what you are saying and that makes sense. The only thing that has changed with my setup is that I was trying out different versions of foobar2k.

Now I just realized that if foobar2k is open when I use the "Send to Apply Gain" from the Explorer context menu, then Mp3tag opens to the correct directory. However, if foobar2k is closed when I use "Send to" then foobar2k opens but MP3tag doesn't. Mp3tag used to open after I applied the replay gain values in f2k and closed the cmd window pop-up. Weird. I guess it's foobar2k related?

You could insert the
echo %1
as the first statement in the batch file to see whether the path is there or not.
Why foobar should swallow the contents of the %1 parameter ... does not make sense

echo %1
as the first statement

I see a filename - whereas /fp likes a path.
To load a file, the parameter /fn would be correct.

Yeah, I don't understand why it shows just the one file when I selected all the files in that folder.
I tried changing to /fn but that didn't help. When I did that, mp3tag opened but only showed the one file rather than all files in the directory.

I don't get why this worked for years but then broke when I installed/uninstalled a bunch of different versions of f2k...

And why does mp3tag open to the correct directory when f2k is open when I do "Send to" but it doesn't open at all if f2k is closed when I do the same thing?

I just tested the script here and it works as intended.
You write that you select all files in a folder. The script ist not intended to work with selected files but with a selected folder. So just select a folder and drag it to the batch file or use "Send to".

I use Foobar v1.5.3 but I can't figure out how to apply the context menu functions using the command line.
Please tell us your Foobar version and post a command line that completes the "Scan selection as albums (by tags)" function. :slightly_smiling_face:
The one used in the O.P.'s batch file doesn't work for me.

Before it stopped working, I could do it either way. Now neither way works like it used to..

Installing and uninstalling a bunch of different versions of f2k must've messed something up, since that's the only change that I've done between the time the bat file was working and now. Maybe something in the registry got changed?

What version of f2k are you using?

I had to go back to the really old version of foobar that I was originally using to get the foobar portion to work like it used to - Foobar2000 - v1.3.13

Newer versions of foobar never gave me the prompt to update the file tags.

Going back to the older version fixed the f2k part, but somehow the mp3tag part started acting differently...