# Custom Action to Reorganize a Music Library using Tag Information

**URL:** https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937
**Category:** Support
**Created:** [February 21, 2020, 6:20am UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937 "2020-02-21T06:20:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Gr8Scott](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gr8Scott](https://community.mp3tag.de/u/Gr8Scott)
#### Post date: [February 21, 2020, 6:20am UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/1 "2020-02-21T06:20:28Z")

</div>

This post is not a direct request for help but more of a _ **How-To** _. I felt the need to do this post given the number of times I've seen people request help related to moving files from one directory structure to another using existing tag information. Most of the posts I read didn't appear complete. I'm not saying that this solution is the end-all for everybody but I believe it provides the basis whereby others can modify for their own particular use. However, before moving forward, let me start with this shameless plug.

I've been a big fan of Mp3tag for many years. It's saved me countless hours tagging and organizing all of my music files (both FLAC and MP3). I've donated to Florian in the past and will again soon, especially after this 3.00 release. I encourage everybody to do the same because Florian and his team do outstanding work and the user community is the best. It costs money to host this site, for purchasing development tools and to receive such excellent support so please donate.

This is my contribution for moving all the files contained within one folder/directory structure to another and reorganized based upon music file tag information. However, before discussing this specific solution, let me provide some background information.

**ASSUMPTIONS:**

- The music files of interest are contained within the following working directory: **`C:\Users\Scott\Music\Working`**
- All of the music files in the working directory, including any sub-folders within it, are properly named and tagged.
- In addition to being properly named and tagged, music files in sub-folders may include cover art (e.g. folder.jpg).

**GOALS:**

- I want to re-organize the music files in my working directory into a new destination directory as follows: **`C:\Users\Scott\Music\_Reorganized\Album Artist\[Year] Album\filename.ext`**
- I don't want to use the built-in _Convert Filename - Tag_ functionality. Instead, I want to create an action group.
- I chose an action group so that (1) it'll work for any working directory, and (2) allows adding other actions at a later date.

Yeah, I know, that was a lot of information to digest. The good news is that the solution is actually fairly simple. So let's go through the steps I performed to achieve the goals stated above.

**STEPS:**

1. Using the Action menu, I created a New action group called: _Reorganize Music Library (WARNING - Moves && Deletes files)_
2. I then created a New action as follows:  
**Action Type:** Format value  
**Field:** \_DIRECTORY  
**Format String:** `$cutRight(%_workingpath%,$add($len(%_workingdir%),1))\_Reorganized\%albumartist%\'['%srcyear%']' %album%\`

- Please note that I have a user-defined tag called _SRCYEAR_ (i.e. _%srcyear%_) where I store the _Year_ when a specific _Album_ from a specific _Album Artist_ was released. You may need to modify this tag for your given situation.

1. Finally, save this _Action_ in the _Action Group_.

**USAGE:**  
To reorganize the music files in the working directory:

- If you're not already in the correct working directory, from the menu select _File -\> Change Directory_. In the pop-up dialogue box, make sure (1) the _Sub-directories_ checkbox is checked then (2) select the working directory: **`C:\Users\Scott\Music\Working`**
- After a moment, all of the music files should become visible on the screen.
- On the keyboard, select all music files using the shortcut: [CTRL] [A]
- From the menu, select _Actions -\> Reorganize Music Library (WARNING - Moves & Deletes files)_
- After a moment, the "Writing tag data" pop-up window will disappear
- DO NOT CLOSE Mp3tag, yet.
- Your reorganized files should be located here: **`C:\Users\Scott\Music\_Reorganized`**

**NOTES:**

1. If the reorganized files in the new directory are not what you are expecting, go back to Mp3tag and from the keyboard, use the shortcut [CTRL] [Z] to undo the action.
2. After executing this script, all music files in the working directory that share the same _Album Artist_, _Year_ and _Album_ tag data will be relocated into a common destination directory. Therefore, any duplicate music, cover art or other file(s) from the original working directory will require a manual confirmation to overwrite EACH duplicate that's identified in the destination directory. _ **Be cautious when using this script on directories containing a large quantity of files.** _
3. The working directory will have empty folders that need to be removed manually. That's one of the _Actions_ I will add to the _Action Group_ at a later date.
4. I had to do some "trickery" to get the destination directory to work correctly. In short, **`%_workingpath%`** is the full path to the Mp3tag working directory and **`$cutRight(%_workingpath%,$add($len(%_workingdir%),1))`** puts me in the directory above.

Well, that's my solution for reorganizing directories based upon the tag information. Admittedly, this may not be the most elegant solution but it appears to be working properly from the testing I've run on it thus far. Feel free to use or modify what I provided but remember, you assume all risks;)

I've been very busy at work so I'm pressed for time. If anybody can enhance this action group to automatically remove empty directories from the working directory, you would have my gratitude!

---

<div class="post-metadata">

### Author: ![Gr8Scott](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gr8Scott](https://community.mp3tag.de/u/Gr8Scott)
#### Post date: [June 28, 2021, 3:34am UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/2 "2021-06-28T03:34:37Z")

</div>

I realized that this post only works with music files that have already been organized into sub-directories (e.g. by Artist). If your songs are not already organized in this manner, the change listed below will organize your music files regardless if they're in sub-directories or not.

> [@Gr8Scott](#):
>
> **STEPS:**
> 
> 1. Using the Action menu, I created a New action group called: _Reorganize Music Library (WARNING - Moves && Deletes files)_
> 2. I then created a New action as follows:  
> **Action Type:** Format value  
> **Field:** \* \_FILENAME  
> **Format String:** `$cutRight(%_workingpath%,$add($len(%_workingdir%),1))\_Reorganized\%albumartist%\'['%srcyear%']' %album%\`
> 
> - Please note that I have a user-defined tag called _SRCYEAR_ (i.e. _%srcyear%_) where I store the _Year_ when a specific _Album_ from a specific _Album Artist_ was released. You may need to modify this tag for your given situation.
> 
> 1. Finally, save this _Action_ in the _Action Group_.

As before, this _Action_ assumes that all the tags in the music files are valid. This should serve as a good starting point for organizing your music files. I have a more sophisticated version that includes enhanced error checking and will post it here if sufficient interest is expressed.

---

<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 28, 2021, 4:28am UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/3 "2021-06-28T04:28:27Z")

</div>

There are 2 things I'd like to note:

The format string

> [@Gr8Scott](#):
>
> $cutRight(%\_workingpath%,$add($len(%\_workingdir%),1))\_Reorganized%albumartist%'['%srcyear%']' %album%\

only describes the path-part. If you really want to move a file to a new folder and you modify the \_FILENAME for that, you also need to add a part that describes the actual filename., e.g.  
`$cutRight(%_workingpath%,$add($len(%_workingdir%),1))\_Reorganize\%albumartist%\'['%srcyear%']' %album%\%_filename%`

There is a standard tag field that has the same role as the user-defined tag field

> [@Gr8Scott](#):
>
> _SRCYEAR_

that you use:

> [@Gr8Scott](#):
>
> where I store the _Year_ when a specific _Album_ from a specific _Album Artist_ was released

ORIGYEAR.  
As not all players support user-defined fields (and just as few support all standard tag-fields) it may still be a good idea to cling to the standard.  
For all other users I would recommend to use the field  
YEAR.

---

<div class="post-metadata">

### Author: ![Gr8Scott](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gr8Scott](https://community.mp3tag.de/u/Gr8Scott)
#### Post date: [June 29, 2021, 4:36am UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/4 "2021-06-29T04:36:19Z")

</div>

Thank you for pointing out my error in the _Format String_. I was in a hurry and accidentally posted this rather than saving it as a draft. Additionally, being a newbie with scripting, I appreciate any feedback that improves my skills.

---

<div class="post-metadata">

### Author: ![tsubasa.k111](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@tsubasa.k111](https://community.mp3tag.de/u/tsubasa.k111)
#### Post date: [February 4, 2025, 7:22am UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/5 "2025-02-04T07:22:54Z")

</div>

For MacOS and linux/BSD users:  
This solution did not work for me on MacOS due to permission issues, but what did work is something like this:

Format Tag Field `_FILENAME` to  
`../_reorganized/%albumartist% - %album%/%track% %artist% - %title%`

It seemed like mp3tag was unable to obtain the `%_workingdir%` or `%_workingpath%` string values.

---

<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: [February 4, 2025, 7:26am UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/6 "2025-02-04T07:26:27Z")

</div>

> [@tsubasa.k111](#):
>
> MacOS due to permission issues

If the denied permissions have their origin in the bookmarks, see this thread:

> [@Cannot access file via secure bookmark mp3tag mac](https://community.mp3tag.de/t/cannot-access-file-via-secure-bookmark-mp3tag-mac/62298):
>
> Similar issue to # [Cannot access file XYZ via secure bookmark](https://community.mp3tag.de/t/cannot-access-file-xyz-via-secure-bookmark/55728) I recently upgraded to Mac OS Sonoma & this issue which was resolved is back and the fixes don't seem to work

---

<div class="post-metadata">

### Author: ![EMCO](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@EMCO](https://community.mp3tag.de/u/EMCO)
#### Post date: [February 4, 2025, 5:44pm UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/7 "2025-02-04T17:44:54Z")

</div>

Because i'm lac on double files i use the folow:  
`M:\MUZIEK\$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)\%artist%\%artist% - %title%`

you can change M:\MUZIEK\ to your needs.

And all my music have the alphabet like Maps AAA, BBB, CCC... then ARTIST folders with ARTIST - TITLE.mp3

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [February 4, 2025, 7:53pm UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/8 "2025-02-04T19:53:04Z")

</div>

> [@EMCO](#):
>
> $left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)%artist%%artist% - %title%

Instead of writing your first letter producing `$left` command 3 times (to get - for example LLL - ), you could just wrap it into 1 `$repeat` as this:  
`$repeat($left($regexp(%artist%,^()\s'('.+')'$,$2,1),1),3)\%artist%\%artist% - %title%`

From the [documentation](https://docs.mp3tag.de/scripting/#string-functions):  
 ![image](https://community.mp3tag.de/uploads/default/original/3X/5/7/57a8d67ae18b8beaa619090ae79e7d5ed93f731d.png)

---

<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: [March 6, 2025, 7:53pm UTC](https://community.mp3tag.de/t/custom-action-to-reorganize-a-music-library-using-tag-information/47937/9 "2025-03-06T19:53:55Z")

</div>

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