# Directory Renaming Recursively

**URL:** <https://community.mp3tag.de/t/directory-renaming-recursively/15542>\
**Category:** Support\
**Created:** [February 26, 2014, 1:12pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542 "2014-02-26T13:12:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CC-GoE](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/b38774/32.png) [@CC-GoE](https://community.mp3tag.de/u/CC-GoE)\
**Post date:** [February 26, 2014, 1:12pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/1 "2014-02-26T13:12:25Z")

</div>

HI!  
I have a directory structure of:

[Root]\Artist\Year - Album(tracks...)

Example:

[Root]\Amy Winehouse\2003 - Frank(tracks...)

I want to replace:

2003 - Frank

with:

(2003) Frank

or perhaps

[2003] Frank

Now I found an action that suits me for this purpose:

```
Replace with regular expression:
Field:
_DIRECTORY
Regular expression:
(\d\d\d\d)\s-\s
Replace matches with:
($1) $2

```

I tested it and it works. My question is:  
Is it possible to apply this action recursively now, for a bigger directory tree?

---

<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:** [February 26, 2014, 1:33pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/2 "2014-02-26T13:33:20Z")

</div>

> [@CC-GoE](#):
>
> I have a directory structure of:
> 
> [Root]\Artist\Year - Album(tracks...)

Why not build the wanted directory new instead of changing parts of the existing directory?

Action-Type: Format Value  
Field: \_directoty  
Format string: \%artist%[%year%] %album%

---

<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 26, 2014, 6:12pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/3 "2014-02-26T18:12:13Z")

</div>

> [@CC-GoE](#):
>
> ...  
> Is it possible to apply this action recursively now, for a bigger directory tree?

I agree with poster that an action of the type "Format value" is better suited for the purpose.  
The pseudo-variable \_DIRECTORY addresses the folder "above" the filename.  
So: yes, any folders you have loaded will be renamed according to the pattern you define in the "format value" action.

---

<div class="post-metadata">

**Author:** ![CC-GoE](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/b38774/32.png) [@CC-GoE](https://community.mp3tag.de/u/CC-GoE)\
**Post date:** [February 26, 2014, 6:23pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/4 "2014-02-26T18:23:20Z")

</div>

> [@ohrenkino](#):
>
> I agree with poster that an action of the type "Format value" is better suited for the purpose.  
> The pseudo-variable \_DIRECTORY addresses the folder "above" the filename.  
> So: yes, any folders you have loaded will be renamed according to the pattern you define in the "format value" action.

OK!  
Well I will give it a try...  
I just wanted to correct my post.  
Actually, I am not looking for "recursive", as my directory depth is always the same.  
As I described above.  
I just want to apply the action, "iteratively", on a long directory list of artists.  
Thanks though.  
I will post back maybe with my results.  
But, can the "Format Value" action, be applied on many artists directories? Lets see...

EDIT: OK first things first.  
According to: [https://docs.mp3tag.de/scripting](https://docs.mp3tag.de/scripting)

> [@](#):
>
> $% You have to put a single quote around these reserved characters if you want to use them unparsed.

So its: Format string: \%artist%'['%year%']' %album%

Still, I cant make it work this far...  
What I get, is empty folders.  
Is this what you meant?  
You see, I want to have the MP3s inside those folders...  
I am doing something wrong...

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [February 26, 2014, 7:27pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/5 "2014-02-26T19:27:28Z")

</div>

> [@CC-GoE](#):
>
> ... What I get, is empty folders. ... I am doing something wrong...

This should work ...

**Set Filter:**

**"%\_DIRECTORY%" MATCHES "(\d\d\d\d)\s-\s"**

  

Action: Format value  
... or ...  
Converter: Tag - Tag  
Field: \_DIRECTORY  
Formatstring: $regexp(%\_directory%,'(\d\d\d\d)\s-\s','($1) ')

 ... or ... 

**Formatstring: $regexp(%\_directory%,'(\d\d\d\d)\s-\s','[$1] ')**

 

Mp3tag performs the filesystem procedure "MOVE folder" with all files in the specified folder.

 

DD.20140226.2127.CET

 

I have removed the $2 referrer in the replacement part of the regexp, because it was not declared in the expression and it is actually not needed.

 

DD.20140227.0912.CET

---

<div class="post-metadata">

**Author:** ![CC-GoE](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/b38774/32.png) [@CC-GoE](https://community.mp3tag.de/u/CC-GoE)\
**Post date:** [February 27, 2014, 5:14am UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/6 "2014-02-27T05:14:12Z")

</div>

> [@DetlevD](#):
>
> This should work ...
> 
> **Set Filter:**
> 
> **"%\_DIRECTORY%" MATCHES "(\d\d\d\d)\s-\s"**
> 
>   
> 
> Action: Format value  
> ... or ...  
> Converter: Tag - Tag  
> Field: \_DIRECTORY  
> Formatstring: $regexp(%\_directory%,'(\d\d\d\d)\s-\s','($1) $2')
> 
> ... or ... 
> 
> **Formatstring: $regexp(%\_directory%,'(\d\d\d\d)\s-\s','[$1] $2')**
> 
>  
> 
> Mp3tag performs the filesystem procedure "MOVE folder" with all files in the specified folder.
> 
>  
> 
> DD.20140226.2127.CET

IT WORKED! Absolutely brilliant!  
Great work DetlevD.

For anyone interested, I figured out the opposite.  
From a directory containing:

[2013] ThisAlbum

to:

2013 - ThisAlbum

```
Filter:
"%_DIRECTORY%" MATCHES "([[])(\d\d\d\d)([]])"

Format Value:
Field:
_DIRECTORY
Format string:
$regexp(%_directory%,'([[])(\d\d\d\d)([]])','$2 -$4')

```

PS: Please test this first with some samples...  
Also others can verify if this code is OK...

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [February 27, 2014, 7:11am UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/7 "2014-02-27T07:11:07Z")

</div>

> [@CC-GoE](#):
>
> ... Also others can verify if this code is OK...

 

Set Filter for four digits and one space character at the first position,  
with the number surrounded by ...

 

... round brackets  
"%\_DIRECTORY%" MATCHES "^(\d{4})\s"

 

... square brackets  
"%\_DIRECTORY%" MATCHES "^[\d{4}]\s"

 

... curly brackets  
"%\_DIRECTORY%" MATCHES "^{\d{4}}\s"

 

... round or square or curly brackets  
"%\_DIRECTORY%" MATCHES "\[1\]\s"

 

Remove brackets ...  
Action: Format value  
... or ...  
Converter "Tag - Tag"  
Field: \_DIRECTORY

 

... round brackets  
Formatstring: $regexp(%\_directory%,'^((\d{4}))\s','$1 ')

 

... square brackets  
Formatstring: $regexp(%\_directory%,'^[(\d{4})]\s','$1 ')

 

... curly brackets  
Formatstring: $regexp(%\_directory%,'^{(\d{4})}\s','$1 ')

 

**... round or square or curly brackets  
Formatstring: $regexp(%\_directory%,'\[2\]\s','$1 ')**

 

DD.20140227.0911.CET

 
* * *
 
1. [({]\d{4})} 

2. ({)}

---

<div class="post-metadata">

**Author:** ![CC-GoE](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/b38774/32.png) [@CC-GoE](https://community.mp3tag.de/u/CC-GoE)\
**Post date:** [February 27, 2014, 4:59pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/8 "2014-02-27T16:59:05Z")

</div>

> [@DetlevD](#):
>
> Set Filter for four digits and one space character at the first position,  
> with the number surrounded by ...
> 
>  
> 
> ... round brackets  
> "%\_DIRECTORY%" MATCHES "^(\d{4})\s"
> 
>  
> 
> ... square brackets  
> "%\_DIRECTORY%" MATCHES "^[\d{4}]\s"
> 
>  
> 
> ... curly brackets  
> "%\_DIRECTORY%" MATCHES "^{\d{4}}\s"
> 
>  
> 
> ... round or square or curly brackets  
> "%\_DIRECTORY%" MATCHES "\[1\]\s"
> 
>  
> 
> Remove brackets ...  
> Action: Format value  
> ... or ...  
> Converter "Tag - Tag"  
> Field: \_DIRECTORY
> 
>  
> 
> ... round brackets  
> Formatstring: $regexp(%\_directory%,'^((\d{4}))\s','$1 ')
> 
>  
> 
> ... square brackets  
> Formatstring: $regexp(%\_directory%,'^[(\d{4})]\s','$1 ')
> 
>  
> 
> ... curly brackets  
> Formatstring: $regexp(%\_directory%,'^{(\d{4})}\s','$1 ')
> 
>  
> 
> **... round or square or curly brackets  
> Formatstring: $regexp(%\_directory%,'\[2\]\s','$1 ')**
> 
>  
> 
> DD.20140227.0911.CET

HAHAaaaaaa.  
EVEN better.  
First, it has the ^ character for matching the start of a line.  
This makes it more secure, as I was worried about possible collisions with albums that have a year as part of their titles.  
Then, a nice touch with more compact \d{4}.  
And also, that we don't need $2, just $1.  
Nice...

* * *

1. [({]\d{4})} 

2. ({)}

---

<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:** [February 9, 2026, 12:24pm UTC](https://community.mp3tag.de/t/directory-renaming-recursively/15542/9 "2026-02-09T12:24:56Z")

</div>

Closed on February 9, 2026, 12:24pm UTC


