# Replace a fixed text string (in File Name) with a variable %year%

**URL:** https://community.mp3tag.de/t/replace-a-fixed-text-string-in-file-name-with-a-variable-year/60676
**Category:** Support
**Created:** [April 11, 2023, 12:57pm UTC](https://community.mp3tag.de/t/replace-a-fixed-text-string-in-file-name-with-a-variable-year/60676 "2023-04-11T12:57:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dec](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dec/32/13699_2.png) [@dec](https://community.mp3tag.de/u/dec)
#### Post date: [April 11, 2023, 12:57pm UTC](https://community.mp3tag.de/t/replace-a-fixed-text-string-in-file-name-with-a-variable-year/60676/1 "2023-04-11T12:57:02Z")

</div>

i have tried all sorts in both Convert and in Actions

this is one example ...

$replace(%filename%,YEAR UNK,%year%)

in this attempt the Year variable was treated as text string

what makes this harder than just appending Year to File Name is that at some point, for SOME files, in an earlier attempt to add year to File name, it didn't work for all, and instead i ended up with a default text string of '(YEAR UNK)', and i can't just append again, because i would end up with a lot that would then have Year twice.

and this raises the question of the technical difference between the Convert function and the Action function: it seems that they are not interchangeable  
eg  
can variables eg %year% be used in both?  
can operators eg $replace be used in both?

---

<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: [April 11, 2023, 1:05pm UTC](https://community.mp3tag.de/t/replace-a-fixed-text-string-in-file-name-with-a-variable-year/60676/2 "2023-04-11T13:05:11Z")

</div>

%year% can be used where you are expected to enter a format string.

> [@dec](#):
>
> this is one example ...
> 
> $replace(%filename%,YEAR UNK,%year%)

If that is the accurate copy then you have replaced the string "YEAR UNK" with the value from YEAR in the user-defined (and probably non-existent) field FILENAME.  
if you want to address the filename, use \_FILENAME.  
Sometimes, as said in

> [@Hints for asking Support Requests](https://community.mp3tag.de/t/hints-for-asking-support-requests/56190):
>
> If you need support using Mp3tag, you can help the community members that are about to support you in finding a solution or workaround to your problem, by following these simple guidelines. Be descriptive, also in what you’ve already tried Please give a short explanation what’s not working as expected or what you’re trying to achieve. It’s best to know any details about the problem at hand and especially, what steps you’ve already tried to solve it by yourself. Helpful information also includ…

a screendump helps.

You say that you have used

> [@dec](#):
>
> both Convert and in Actions

but you do not tell us which Convert function you used and which action.

---

<div class="post-metadata">

### Author: ![MotleyG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/motleyg/32/440_2.png) [@MotleyG](https://community.mp3tag.de/u/MotleyG)
#### Post date: [April 11, 2023, 1:48pm UTC](https://community.mp3tag.de/t/replace-a-fixed-text-string-in-file-name-with-a-variable-year/60676/3 "2023-04-11T13:48:19Z")

</div>

> [@dec](#):
>
> and this raises the question of the technical difference between the Convert function and the Action function: it seems that they are not interchangeable  
> eg  
> can variables eg %year% be used in both?  
> can operators eg $replace be used in both?

The scripting functions can be used effectively in almost all areas of mp3tag where tag editing and filtering is available.

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

The Actions are key for those sequences that you may be running often, as they can be saved and recalled quickly.

The Convert options are more specific to the way you want to address converting to and/or from tags and filename information. But more importantly they also offer the benefit of a live preview of the conversion using your scripting, so you can confirm if the output will be the intended result.

Either way, it is highly recommended that you start with just a single or smaller batch of files, before unleashing any script on an entire library. And it goes without saying that keeping an active and up to date backup of your library is critical.

---

<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: [May 11, 2023, 1:48pm UTC](https://community.mp3tag.de/t/replace-a-fixed-text-string-in-file-name-with-a-variable-year/60676/4 "2023-05-11T13:48:31Z")

</div>

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