Writing Filenames into mp3 Tags with a Batch File

Yesterday I showed how to write from a filename into a jpeg caption and comment. After writing that up I was carrying along with my work, which at the moment entails making 251 mp3s for a section by section reading of my new book (about which more later).

And there again I came across the same problem that I need to write a partial file name into the mp3 title tag. Up and till now I have been using Eags On!, which is a great tag writer, and I was quite satisfied with it – it can write the filename to the tag, and many other useful functions.

However, it can’t write only part of the name, which is what I needed, and therefore I was faced with the prospect of having to do a lot of editing of the title by hand. On one or two files that is OK, on 251 it is most certainly not.

This is what the filenames look like in FreeCommander:

Filenames in FreeCommander

They are very similar to the image files I was demonstrating yesterday. I had just written up that post and it occurred to me if we can do it for .jpegs we can do it for .mp3s also ! so I set out to find a command line utility.

I tried a couple but the one that eventually worked for me was metamp3. With that downloaded and copied into my programs folder. I was ready to set up the batchfile.

It is essentially a hack of yesterday’s file, with the necessary changes. I first got it to write the title – but if it can write the title, then it can write every other tag I need to include also, which also saves me writing the same information out each time I start up a GUI tagger.

Some of the tags are always the same, like ARTIST, GENRE, COMMENT; some vary according to project like ALBUM and YEAR; some have to be grabbed from the filename like TRACK and TITLE. Below is the heavily annotated script, which shows how it is done.

@echo off


REM these do not vary between projects
REM so they can be entered one time here
REM Leave spaces in and do not use quotation markers
SET ARTIST=Anandajoti Bhikkhu    
SET COMMENT=ancient-buddhist-texts.net

REM these do not vary between files in this project
REM so they can be changed for each project
REM Leave spaces in and do not use quotation markers
SET ALBUM=Buddhist Wisdom Verses

REM these four lines empty the variables
REM which will vary according to the filename

REM COUNT is set to zero

REM the loop starts here
FOR %%f IN (*.mp3) do (

REM Here I am taking the title
REM from the 5th character of the filename upto 4 before the end
REM Example: "001 One should be Amenable to Admonition.mp3" 
REM becomes: "One should be Amenable to Admonition"
REM if you want the whole filename (excluding the extension)
REM change the following line to: SET TITLE=!FILE:~1,-4!

REM Here I am taking the track number 
REM from the 1st character of the filename upto the 3rd
REM Example: "001 One should be Amenable to Admonition.mp3" 
REM becomes: "001" [but it shows as 1 in the file]

REM this is writing the info if you have Tag.exe 
REM somewhere else you will need to change the address
REM the ^ character is the line continuation marker
"c:\program files\metamp3\metamp3" ^
--title "!TITLE!"  ^
--artist "!ARTIST!" ^
--album "!ALBUM!" ^
--year "!YEAR!" ^
--genre "!GENRE!" ^
--comment "!COMMENT!" ^
--track "!TRACK!" ^

set /a COUNT=!COUNT!+1

REM emptying the variables again


Here is the output as read in PowerCmd:

Windows Command Line Tool


I might add here that metamp3 can do much much more than I am demonstrating here, including altering the mp3 gain, writing image files in and changing many more tags.

It is easy to change the above code to whatever is useful to you after downloading the programme and seeing what parameters are allowed.


For it to work you have to copy the lines above into a text file, and save it as Tags.bat (or some such name, but with the .bat extension) and move the batchfile to the directory you want to change, and double-click it.

It will only change metadata in the .mp3s, but note it will change all the .mp3s in the directory.

Again, I hope this might help someone having the same problem.


Possibly Related Posts:

3 comments to Writing Filenames into mp3 Tags with a Batch File

  • Ian

    Does not work!

  • You need to update this to use double quotes (“) instead of single quotes in the metamp3 call. Also, there is a beta version of metamp3 that does not require an additional download/install (vc sp1); much better to use the v092b5 version than the one you have a link to.

  • Anandajoti

    Hi Mark, I have updated now. The page I link to seems to have the beta version listed also?

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>