# Windows bat file for Foobar Replay Gain & MP3Tag

**URL:** <https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560>\
**Category:** Support\
**Created:** [December 19, 2021, 12:40am UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560 "2021-12-19T00:40:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 12:40am UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/1 "2021-12-19T00:40:40Z")

</div>

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
exit

:errorfoobar
echo Foobar2000 exited abnormally, ending script
pause
exit

:errormp3tag
echo MP3Tag exited abnormally, ending script
pause
exit
```

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [December 19, 2021, 9:43am UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/2 "2021-12-19T09:43:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)\
**Post date:** [December 19, 2021, 10:23am UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/3 "2021-12-19T10:23:35Z")

</div>

> [@GMahal](#):
>
> `%PROGRAMFILES(x86)%\Mp3tag\mp3tag.exe`

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.

![Search-Mp3tag](https://community.mp3tag.de/uploads/default/original/2X/9/9b2d33c3a8cd7b31ceb5000138ddf4d17a89264e.gif)

Update:  
~~And maybe you should [enclose your %1](https://docs.mp3tag.de/command-line) like this  
 ` /fp:"%1"`  
to avoid problems with directories or filenames containing a space.~~

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [December 19, 2021, 12:37pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/4 "2021-12-19T12:37:41Z")

</div>

> [@LyricsLover](#):
>
> And maybe you should [enclose your %1](https://docs.mp3tag.de/command-line) like this  
> ` /fp:"%1"`  
> 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:  
[https://weblogs.asp.net/jongalloway/top-10-dos-batch-tips-yes-dos-batch#57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:ed9c5366-94e9-42a5-b650-8be6a01e0623](https://weblogs.asp.net/jongalloway/top-10-dos-batch-tips-yes-dos-batch#57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:ed9c5366-94e9-42a5-b650-8be6a01e0623)

---

<div class="post-metadata">

**Author:** ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)\
**Post date:** [December 19, 2021, 12:43pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/5 "2021-12-19T12:43:53Z")

</div>

So you say, the [official help](https://docs.mp3tag.de/command-line) 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:

 ![image](https://community.mp3tag.de/uploads/default/original/2X/7/7ce6edc5c2c945ea8d93c8c485fc641d485e55f0.png)  
otherwise you get this errors:  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/f/f758063e54498abc1d2c3c61901d5b4f9cb26675.png)

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 3:31pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/6 "2021-12-19T15:31:51Z")

</div>

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

![Capture](https://community.mp3tag.de/uploads/default/original/2X/7/71ad383fca4cbd60002478d8f42d0d574ab8c810.jpeg)

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

---

<div class="post-metadata">

**Author:** ![poster](https://community.mp3tag.de/user_avatar/community.mp3tag.de/poster/32/4881_2.png) [@poster](https://community.mp3tag.de/u/poster)\
**Post date:** [December 19, 2021, 3:48pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/7 "2021-12-19T15:48:07Z")

</div>

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

```auto
echo %1
pause

```

before "echo sending .."

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [December 19, 2021, 3:49pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/8 "2021-12-19T15:49:41Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 4:05pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/9 "2021-12-19T16:05:43Z")

</div>

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  
pause

before "echo sending..." as suggested

![Capture1](https://community.mp3tag.de/uploads/default/original/2X/a/ad634ddb2ac1cb31513c2459e3e2d3095130339e.jpeg)

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [December 19, 2021, 4:21pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/10 "2021-12-19T16:21:31Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 4:53pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/11 "2021-12-19T16:53:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [December 19, 2021, 5:00pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/12 "2021-12-19T17:00:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 5:24pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/13 "2021-12-19T17:24:36Z")

</div>

added  
`echo %1`  
as the first statement

 ![Capture2](https://community.mp3tag.de/uploads/default/original/2X/5/57abac1e23be8ec2896164ff2c747548a8dbfbe1.jpeg)

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [December 19, 2021, 5:57pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/14 "2021-12-19T17:57:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 6:44pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/15 "2021-12-19T18:44:20Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 6:46pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/16 "2021-12-19T18:46:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![poster](https://community.mp3tag.de/user_avatar/community.mp3tag.de/poster/32/4881_2.png) [@poster](https://community.mp3tag.de/u/poster)\
**Post date:** [December 19, 2021, 9:06pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/17 "2021-12-19T21:06:08Z")

</div>

> [@GMahal](#):
>
> Yeah, I don't understand why it shows just the one file when I selected all the files in that folder.

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".

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [December 19, 2021, 9:37pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/18 "2021-12-19T21:37:35Z")

</div>

> [@poster](#):
>
> I just tested the script here and it works as intended.

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. 🙂  
The one used in the O.P.'s batch file doesn't work for me.

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 10:38pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/19 "2021-12-19T22:38:09Z")

</div>

> [@poster](#):
>
> 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".

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?

---

<div class="post-metadata">

**Author:** ![GMahal](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@GMahal](https://community.mp3tag.de/u/GMahal)\
**Post date:** [December 19, 2021, 10:43pm UTC](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560/20 "2021-12-19T22:43:38Z")

</div>

> [@ryerman](#):
>
> > [@poster](#):
> >
> > I just tested the script here and it works as intended.
> 
> 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. 🙂  
> The one used in the O.P.'s batch file doesn't work for me.

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...

[Next page](https://community.mp3tag.de/t/windows-bat-file-for-foobar-replay-gain-mp3tag/55560.md?page=2)
