# Swapping Colons in tags for dashes in filenames?

**URL:** <https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661>\
**Category:** Support\
**Created:** [June 18, 2022, 7:27am UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661 "2022-06-18T07:27:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dr\_H\_Vanderbear](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/958977/32.png) [@Dr\_H\_Vanderbear](https://community.mp3tag.de/u/Dr_H_Vanderbear)\
**Post date:** [June 18, 2022, 7:27am UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/1 "2022-06-18T07:27:29Z")

</div>

I LOVE THIS PROGRAM. It's rekindled my enjoyment of music.

Some of my tags use characters that are forbidden in filenames. This file, for example, uses a colon and a slash in two of its tags:

**Artist:** Star Wars  
**Title:** The Desert / The Robot Auction  
**Album:** Episode IV: A New Hope  
**Track:** 04  
**Year:** 1977

When using the "Tag - Filename" command, I get a filename that looks like this:  
**Star Wars \_ Episode IV A New Hope \_ 04 \_ 1977 \_ The Desert The Robot Auction.mp3**

It replaces the colon found in the Album tag and the slashes found in the Title tag with double-spaces.

Is it possible to get the program to substitute a " : " with a " - " and a " / " with a "+" when using the "Tag - Filename" command?

**Desired Filename:** Star Wars \_ Episode IV - A New Hope \_ 04 \_ 1977 \_ The Desert + The Robot Auction.mp3

---

<div class="post-metadata">

**Author:** ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)\
**Post date:** [June 18, 2022, 7:48am UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/2 "2022-06-18T07:48:45Z")

</div>

> [@Dr\_H\_Vanderbear](#):
>
> Is it possible to get the program to substitute a " : " with a " - " and a " / " with a "+" when using the "Tag - Filename" command?

Yes: `$replace(%artist% _ %album% _ %track% _ %year% _ %title%,:,-,/,+)`

> **[Scripting Functions – Mp3tag Documentation](https://docs.mp3tag.de/scripting/#string-functions)**
>
> Documentation on Mp3tag's scripting functions. Mp3tag is the universal Tag Editor.

---

<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:** [June 18, 2022, 7:49am UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/3 "2022-06-18T07:49:05Z")

</div>

You could enclose the whole expression that you normaly use in Converter\>Tag-Filename into the scripting command $replace()  
Like  
`$replace(%artist% _ %album% _ $num(%track%,2) _ %year% _ %title%,:,-,/,+)`

---

<div class="post-metadata">

**Author:** ![Dr\_H\_Vanderbear](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/958977/32.png) [@Dr\_H\_Vanderbear](https://community.mp3tag.de/u/Dr_H_Vanderbear)\
**Post date:** [June 18, 2022, 12:16pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/4 "2022-06-18T12:16:34Z")

</div>

Thanks so much! This worked perfectly.

How can I reverse this so the "Filename - Tag" command transposes colons and slashes back the other way?

So, from this:

**Star Wars \_ Episode IV - A New Hope \_ 04 \_ 1977 \_ The Desert + The Robot Auction.mp3**

To this:

**Artist:** Star Wars  
**Title:** The Desert / The Robot Auction  
**Album:** Episode IV: A New Hope  
**Track:** 04  
**Year:** 1977

---

<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:** [June 18, 2022, 12:23pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/5 "2022-06-18T12:23:08Z")

</div>

If you use Converter Filename-Tag, then you would have to treat the fields afterwards with an action group to replace the characters again.

Or use an action of the type "Guess values" in which you replace the characters before you import the data into the separate fields.

---

<div class="post-metadata">

**Author:** ![Dr\_H\_Vanderbear](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/958977/32.png) [@Dr\_H\_Vanderbear](https://community.mp3tag.de/u/Dr_H_Vanderbear)\
**Post date:** [June 18, 2022, 12:28pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/6 "2022-06-18T12:28:42Z")

</div>

Thank you. I'm trying to do what you've suggested, but I am a novice at coding in general.

I know where to find "Guess Values," but I cannot figure out what the string would look like.

---

<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:** [June 18, 2022, 12:33pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/7 "2022-06-18T12:33:11Z")

</div>

> [@ohrenkino](#):
>
> $replace(%artist% \_ %album% \_ $num(%track%,2) \_ %year% \_ %title%,:,-,/,+)

Source Pattern: `$replace(%_filename%,-,:,+,/)`  
Target: `%artist% _ %album% _ %track% _ %year% _ %title%`

1 problem will be that the "-" is no unique separator but also a "normal" character. So you will probably get more colons than you originally had.

---

<div class="post-metadata">

**Author:** ![Dr\_H\_Vanderbear](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/958977/32.png) [@Dr\_H\_Vanderbear](https://community.mp3tag.de/u/Dr_H_Vanderbear)\
**Post date:** [June 18, 2022, 12:44pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/8 "2022-06-18T12:44:32Z")

</div>

That worked great. Thanks again!

---

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [June 20, 2022, 2:34pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/9 "2022-06-20T14:34:20Z")

</div>

> [@Dr\_H\_Vanderbear](#):
>
> [...]  
> Is it possible to get the program to substitute a " : " with a " - " and a " / " with a "+" when using the "Tag - Filename" command?  
> [...]

But how will you difference later on a real `+` from a substitute one when seeing such sign in `FILENAME`?

Or if you catastrophically loose your `TITLE`s - how will you properly recreate them form `FILENAME`s when they will have multiple occurrences of `-` sign, each possibly meaning something else?

---

<div class="post-metadata">

**Author:** ![Dr\_H\_Vanderbear](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/958977/32.png) [@Dr\_H\_Vanderbear](https://community.mp3tag.de/u/Dr_H_Vanderbear)\
**Post date:** [June 20, 2022, 9:01pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/10 "2022-06-20T21:01:53Z")

</div>

> [@Zerow](#):
>
> But how will you difference later on a real `+` from a substitute one when seeing such sign in `FILENAME`?
> 
> Or if you catastrophically loose your `TITLE`s - how will you properly recreate them form `FILENAME`s when they will have multiple occurrences of `-` sign, each possibly meaning something else?

Hey there. The conclusion I arrived at was to assign substitute characters for each illegal character. Prior to this, I wrote a bunch of rules for how songs are to be titled, so I don't expect too much issue. I'm on the last leg of re-cataloging 12,000 songs and I haven't found anything glaring. Here's what I'm doing:  
(in tag) becomes (in filename)  
: becomes ~  
/ becomes +  
? becomes ^

My Tag - Filename code looks like this:  
**$replace(%albumartist% \_ %album% \_ $num(%track%,2) \_ %year% \_ %title%,:,~,/,+,?,^)**

Some examples:

**Artist:** Star Wars  
**Album:** Episode IV: A New Hope  
**Track:** 04  
**Year:** 1977  
**Song:** The Desert / The Robot Auction  
**Filename:** Star Wars \_ Episode IV~ A New Hope \_ 04 \_ 1977 \_ The Desert + The Robot Auction.mp3

**Artist:** AC/DC  
**Album:** Live [Deluxe]  
**Track:** 105 (I use "100s" to note disc number on multi-disc albums)  
**Year (in this case, of performance rather than publication:** 1991  
**Song:** Who Made Who? [Live] (performance date) [performance venue]  
**Filename:** AC+DC \_ Live [Deluxe] [Live] \_ 105 \_ 1991 \_ Who Made Who^ [Live] (1991-08-23) [Birmingham N.E.C.].mp3

The only thing I'm at risk of losing is my comment info, which contains precise live performance info (date, location, venue, festival name). I need to find a way to output that.

---

<div class="post-metadata">

**Author:** ![Zerow](https://community.mp3tag.de/user_avatar/community.mp3tag.de/zerow/32/11379_2.png) [@Zerow](https://community.mp3tag.de/u/Zerow)\
**Post date:** [June 21, 2022, 6:07pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/11 "2022-06-21T18:07:12Z")

</div>

I have pretty much the same approach - but just different replacement signs

I chose mine on the basis that I have not seen them in titles and band names and are accessible from keyboard. But of course I had to adjust and unify all naming scheme so that system would not brake upon encountering some very rare cases; and more than once had to adjust parts of it

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [July 21, 2022, 6:07pm UTC](https://community.mp3tag.de/t/swapping-colons-in-tags-for-dashes-in-filenames/57661/12 "2022-07-21T18:07:46Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
