# Tag field only if filename contains a specific string using an action

**URL:** https://community.mp3tag.de/t/tag-field-only-if-filename-contains-a-specific-string-using-an-action/13790
**Category:** General Discussion
**Created:** [August 23, 2012, 3:58am UTC](https://community.mp3tag.de/t/tag-field-only-if-filename-contains-a-specific-string-using-an-action/13790 "2012-08-23T03:58:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ian1](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/ebca7d/32.png) [@Ian1](https://community.mp3tag.de/u/Ian1)
#### Post date: [August 23, 2012, 3:58am UTC](https://community.mp3tag.de/t/tag-field-only-if-filename-contains-a-specific-string-using-an-action/13790/1 "2012-08-23T03:58:54Z")

</div>

Hello, I've been using Mp3Tag for while now, and I was wondering if its possible to make an action that will format a value only if the filename has a specific string in it. My main goal is to have an action to tag my large archive of radio shows based on the filename. Right now, I have actions for each separate radio show, but I would like to be able to simultaneously tag a selection of different show at the same time.

For example, say I have three files -

ShowA - 2012-05-07.mp3  
ShowB - 2012-07-12.mp3  
ShowC - 2012-06-21.mp3

A part of the action could tag the Genre field in each file to -

Political  
Sports  
Religious

I would want the artist field to be formatted with a different artist as well, depending on the show in the filename.

Is this even possible, maybe using if,then,else expressions? I tried reading the help document on expressions, but I couldn't really find any examples specifically for this. Thanks in advance.

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [August 23, 2012, 4:39am UTC](https://community.mp3tag.de/t/tag-field-only-if-filename-contains-a-specific-string-using-an-action/13790/2 "2012-08-23T04:39:57Z")

</div>

This is for ShowA -\> Genre=Political

_Action type:_ **Format value**  
_Field:_ **GENRE**  
_Format string:_ **$if($eql($strstr(%\_filename%,ShowA),1),Political,%genre%)**

It means if the string ShowA is found at the first position of the filename, write Political in the genre. If not keep the old genre value.

---

<div class="post-metadata">

### Author: ![Ian1](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/ebca7d/32.png) [@Ian1](https://community.mp3tag.de/u/Ian1)
#### Post date: [August 23, 2012, 4:55am UTC](https://community.mp3tag.de/t/tag-field-only-if-filename-contains-a-specific-string-using-an-action/13790/3 "2012-08-23T04:55:49Z")

</div>

Hey, thanks for the quick reply man. 🙂 I will have to try that. Will this work for shows with spaces? Also how would I extract the year from the filename if the format is "Show - YYYY-MM-DD"? Without an action type for that, I would need to make an action for each year.

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [August 23, 2012, 5:28am UTC](https://community.mp3tag.de/t/tag-field-only-if-filename-contains-a-specific-string-using-an-action/13790/4 "2012-08-23T05:28:06Z")

</div>

Extracting the year:

_Action type:_ **Guess values**  
_Source format:_ **$regexp(%\_filename%,'^.+(\d\d\d\d)-(\d\d)-(\d\d).\*',\<$1\>)**  
_Guessing pattern:_ **\<%year%\>**

---

<div class="post-metadata">

### Author: ![Ian1](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/ebca7d/32.png) [@Ian1](https://community.mp3tag.de/u/Ian1)
#### Post date: [August 23, 2012, 7:37am UTC](https://community.mp3tag.de/t/tag-field-only-if-filename-contains-a-specific-string-using-an-action/13790/5 "2012-08-23T07:37:31Z")

</div>

Hey thanks for all the help. Since all of my radio shows are consistent, thanks to a handy program called Advanced Renamer, I ended up using %album% - %year%-%dummy%-%dummy% to get the album from the show name and also the year. I'm pretty happy now with my setup, so for those curious I'll share my action setup for tagging radio shows.

For example, for just a show called "Howard Stern Radio Show"

_Action type:_ **Remove fields**  
_Fields to remove:_ **TITLE;ARTIST;ALBUM;ALBUMARTIST;YEAR;COMMENT;TRACK;**

_Action type:_ **Format value**  
_Field:_ **TITLE**  
_Format string:_ **%\_filename%**

_Action type:_ **Format value**  
_Field:_ **ARTIST**  
_Format string:_ **$if($eql($strstr(%\_filename%,Howard Stern Radio Show),1),Howard Stern,%artist%)**

_Action type:_ **Format value**  
_Field:_ **ALBUMARTIST**  
_Format string:_ **%artist%**

_Action type:_ **Format value**  
_Field:_ **GENRE**  
_Format string:_ **Radio**

_Action type:_ **Format value**  
_Field:_ **COMMENT**  
_Format string:_ **$if($eql($strstr(%\_filename%,Howard Stern Radio Show),1),[www.howardstern.com](http://www.howardstern.com),%comment%)**

_Action type:_ **Guess Values**  
_Source format:_ **%\_filename%**  
_Guessing pattern:_ **%album% - %year%-%dummy%-%dummy%**

So, for multiple radio shows, the only tags that need an if expression is the artist and comment. The comment is the show's website. I found you can have multiple if statements in the same Format value entry, instead of needing multiple entries, for multiple shows. Also I decided to just have the genre be Radio for all of the shows.
