# Filename scripting help needed

**URL:** <https://community.mp3tag.de/t/filename-scripting-help-needed/46534>\
**Category:** Support\
**Created:** [September 27, 2019, 2:52am UTC](https://community.mp3tag.de/t/filename-scripting-help-needed/46534 "2019-09-27T02:52:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_Mendelli](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@Mr\_Mendelli](https://community.mp3tag.de/u/Mr_Mendelli)\
**Post date:** [September 27, 2019, 2:52am UTC](https://community.mp3tag.de/t/filename-scripting-help-needed/46534/1 "2019-09-27T02:52:43Z")

</div>

I'm working on scripting a means of renaming my digital movies collection. I'm fairly new to the scripting functionality and need some help getting my filenames renamed a certain way. I need the filenames formatted like so:

`%title% [%year%]`

There are a couple of hurtles to overcome though. I need the script to change the filename to the embedded title _first_, then I need it to add the year in brackets _(`[%year%]`)_ _if_ the year is not already present in the filename. I can get a script that renames the filename to the title and another to add the year, but I need them both done simultaneously. I also need to know how character escaping works in Mp3Tag as I cannot get the brackets to appear around the year in the filename and I need the title to overwrite the original filename as it seems to keep the original filename in addition to adding the title name.

Here is the script I have had the best luck with so far:

![unknown](https://community.mp3tag.de/uploads/default/original/2X/0/089ac4a8f5df503434377d8ae1ca017ddd0fcd1e.png)

---

<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:** [September 27, 2019, 4:28am UTC](https://community.mp3tag.de/t/filename-scripting-help-needed/46534/2 "2019-09-27T04:28:31Z")

</div>

You should build the filename from the tagfields in any case, even if the filenames are already correct with the year.

Your format string for the converter is:  
`%title%['['%year%']']`

With '[' and ']' the brackets get escaped so that they show up. All that is embedded in non-escaped brackets is only taken if the placeholder %year% is present in the file.

---

<div class="post-metadata">

**Author:** ![Mr\_Mendelli](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@Mr\_Mendelli](https://community.mp3tag.de/u/Mr_Mendelli)\
**Post date:** [September 27, 2019, 10:49pm UTC](https://community.mp3tag.de/t/filename-scripting-help-needed/46534/3 "2019-09-27T22:49:34Z")

</div>

Thank you, this worked exactly as I needed.

---

<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:** [October 27, 2019, 11:00pm UTC](https://community.mp3tag.de/t/filename-scripting-help-needed/46534/4 "2019-10-27T23:00:10Z")

</div>

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