# Conditional folder renaming

**URL:** https://community.mp3tag.de/t/conditional-folder-renaming/13840
**Category:** General Discussion
**Created:** [September 4, 2012, 7:12pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840 "2012-09-04T19:12:17Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![aax](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@aax](https://community.mp3tag.de/u/aax)
#### Post date: [September 4, 2012, 7:12pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/1 "2012-09-04T19:12:17Z")

</div>

Right now I use this **Format Value** action to rename a folder:

Field: \_DIRECTORY  
Format string: %album% '['$upper(%\_extension%)']'

Example: \Album title [FLAC]\File.flac

What I would like to do is write an action that would use this format only if there is already a folder with the same name as %album% in the grandparent folder. If not, then it woul use just album name without the extension.

I think that it would require one of the Boolean functions but I don't know how to describe it.

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [September 4, 2012, 7:32pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/2 "2012-09-04T19:32:24Z")

</div>

Mp3tag can't determine if a folder already exists. It can only read the parent and grandparent folder names. If the album were already in the appropriate grandparent folder, then you could do a conditional folder renaming with

_Action type:_ **Format value**  
_Field:_ **\_DIRECTORY**  
_Format string:_ **%album%$if($eql($upper(%\_extension%),%\_parent\_directory%),' ['$upper(%\_extension%)']',)**

---

<div class="post-metadata">

### Author: ![aax](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@aax](https://community.mp3tag.de/u/aax)
#### Post date: [September 4, 2012, 10:31pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/3 "2012-09-04T22:31:22Z")

</div>

I'm sorry, I can't decipher what that string would do. Add the extension to folder name if the grandparent directory is named like uppercased extension? ![:unsure:](https://community.mp3tag.de/uploads/default/original/1X/cfaeba84fe6704387c5b34dfdd8172bd51b6f533.gif ":unsure:")

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [September 4, 2012, 11:19pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/4 "2012-09-04T23:19:54Z")

</div>

> [@aax](#):
>
> I'm sorry, I can't decipher what that string would do. Add the extension to folder name if the grandparent directory is named like uppercased extension?

Yes. Actually, there was a mistake. It should be:

_Action type:_ **Format value**  
_Field:_   
_Format string:_ **%album%$if($eql($upper(%\_extension%),%\_parent\_directory%),' ['$upper(%\_extension%)']',%\_directory%)**

But I see that I misread your post. You wanted this action to disambiguate the folder names for matching albums.

---

<div class="post-metadata">

### Author: ![aax](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@aax](https://community.mp3tag.de/u/aax)
#### Post date: [September 4, 2012, 11:29pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/5 "2012-09-04T23:29:05Z")

</div>

Exactly. But if mp3tag can't check the names of the folders that aren't part of the album path that's all right. I'll just continue using my current action.

---

<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: [September 5, 2012, 5:14am UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/6 "2012-09-05T05:14:20Z")

</div>

> [@JJ Johnson](#):
>
> Mp3tag can't determine if a folder already exists. ...

Yes. Mp3tag currently provides no $FileExist() or $FolderExist() functions.

> [@JJ Johnson](#):
>
> ... It can only read the parent and grandparent folder names. ...

Yes, but not quite right.  
Mp3tag provides two system related pseudo tag-fields ...  
%\_directory% ... the name of the home folder of the media file;  
%\_parent\_directory% ... the name of the folder of the home folder of the media file.

Beside that it is possible to evaluate the complete folderpath, for each folder item, by using the Mp3tag scripting language and actions as described there ...  
[Easy way to get directory names above Parent?](https://community.mp3tag.de/t/9324/6)  
[unterschiedlicher Aufbau von Dateinamen](https://community.mp3tag.de/t/12021/4)

DD.20120905.0935.CEST

---

<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: [September 5, 2012, 5:28am UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/7 "2012-09-05T05:28:07Z")

</div>

> [@aax](#):
>
> ... Format string: %album% '['$upper(%\_extension%)']'  
> Example: \Album title [FLAC]\File.flac  
> What I would like to do is write an action that would use this format only if there is already a folder with the same name as %album% in the grandparent folder. If not, then it woul use just album name without the extension. ...

Hm, maybe ...

**$if($eql(%\_parent\_directory%,%ALBUM%' ['$upper(%\_extension%)']'),%ALBUM%' ['$upper(%\_extension%)']'),%ALBUM%)**

DD.20120905.0927.CEST

---

<div class="post-metadata">

### Author: ![aax](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@aax](https://community.mp3tag.de/u/aax)
#### Post date: [September 5, 2012, 1:59pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/8 "2012-09-05T13:59:14Z")

</div>

Detlev, does your string mean that if grandparent directory is named "Album [EXT]", then parent directory would also be named "Album [EXT]", otherwise it would be named just "Album"?

---

<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: [September 5, 2012, 2:48pm UTC](https://community.mp3tag.de/t/conditional-folder-renaming/13840/9 "2012-09-05T14:48:01Z")

</div>

Yes, I do read the expression the same way too.  
aax, I admit that I did not fully understand the problem and have therefore given only one thinking incentive.  
It is not clear to me, what the "parent directory" or the "directoy" will be searched for, and what should be changed in the "directory".  
It would be helpful if you can show an example of the two cases in their directory tree structure.

DD.20120905.1847.CEST
