# Rename folder with \[

**URL:** <https://community.mp3tag.de/t/rename-folder-with/59241>\
**Category:** Support\
**Created:** [November 30, 2022, 6:32am UTC](https://community.mp3tag.de/t/rename-folder-with/59241 "2022-11-30T06:32:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![viviancels](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/bbe5ce/32.png) [@viviancels](https://community.mp3tag.de/u/viviancels)\
**Post date:** [November 30, 2022, 6:32am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/1 "2022-11-30T06:32:22Z")

</div>

Hello. I try to write command to rename parrent folder.  
Field: \_DIRECTORY  
Format string: [%comment%] %artist% - %album% (%year%)  
Folder must look: [comment] artist - album (year).  
Result whithout []: comment artist - album (year). Maybe [] - special symbols and they must be shielded?

---

<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:** [November 30, 2022, 6:42am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/2 "2022-11-30T06:42:34Z")

</div>

> [@viviancels](#):
>
> they must be shielded

Yes, try:  
Format string: `'['%comment%']' %artist% - %album% (%year%)`

The square brackets serve as "if" condition and designate the part that should only be output if the tag field exists.

See also the documentation:

> **[Format Strings and Placeholders – Mp3tag Documentation](https://docs.mp3tag.de/format/#characters-with-special-functionality)**
>
> Documentation on format strings and placeholders to describe the structure of file names and imported data. Mp3tag is the universal Tag Editor.

---

<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:** [November 30, 2022, 9:49am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/3 "2022-11-30T09:49:06Z")

</div>

> [@viviancels](#):
>
> Hello. I try to write command to rename parrent folder.[  
> Field: \_DIRECTORY

I think you mean the folder and not the parent-folder.

> [@ohrenkino](#):
>
> Format string: `'['%comment%']' %artist% - %album% (%year%)`
> 
> The square brackets serve as "if" condition and designate the part that should only be output if the tag field exists.

You should take 2 things into consideration:

1. An action for the pseudo-tagfield \_DIRECTORY moves all files of a folder to a new directory, not only the marked ones. The content of the first marked file will be responsible where you move all the files in the folder.

2. If COMMENT is empty you will end up with " " before %album%. If this could be a problem use the format string: `['['%comment%']' ]%artist% - %album% (%year%)`. This makes use of the mentioned "if" condition of square brackets.

---

<div class="post-metadata">

**Author:** ![viviancels](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/bbe5ce/32.png) [@viviancels](https://community.mp3tag.de/u/viviancels)\
**Post date:** [December 4, 2022, 10:23am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/4 "2022-12-04T10:23:16Z")

</div>

Thank you for information. Also today I needed to copy part of parent folder ("Catalog number of release" inside the square brackets) to tag and after few tries wrote this command,:

```auto
$regexp(%_DIRECTORY%,'^\[(.*?)\].*(\(\d{4})\)$','$1')

```

Folder name: [Catalog number of release] Artist - Album (year)

---

<div class="post-metadata">

**Author:** ![viviancels](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/bbe5ce/32.png) [@viviancels](https://community.mp3tag.de/u/viviancels)\
**Post date:** [December 11, 2022, 8:01am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/5 "2022-12-11T08:01:20Z")

</div>

Good morning. Again, the problem with square brackets.  
I need import the numbers at the end of the folder name to tag  
First I tried Filename-\>Tag  
Format string:  
`%dummy% (%dummy%) %AlbumID%\%_filename%`

It work well, when folder name is: [] Artist - Album (Year) 43673771  
Result: 43673771  
But if folder name is: [] Artist - Album (Another artist remix) (Year) 43673771  
then result is: (Year) 43673771

Second I tried action "Guess values" with regexp:  
Source format: `$regexp(%_DIRECTORY%, '.*\(\d{4}\) (.*)', '$1')`  
Guessing pattern: %AlbumID%  
or "Format value":  
Field: ALBUMID  
Format string: `$regexp(%_DIRECTORY%, '.*\(\d{4}\) (.*)', '$1')`  
In both cases result is: [] 43673771  
I can't understand where the square brackets come from as a result

I tried shield it:  
`$regexp(%_DIRECTORY%, '^'['']'.*\(\d{4}\) (.*)', '$1')`  
But it dont work.

---

<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:** [December 11, 2022, 8:13am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/6 "2022-12-11T08:13:58Z")

</div>

I cannot reproduce it:  
` $regexp([] Artist - Album (Another artist remix) (2000) 43673771, '.*\(\d{4}\) (.*)', '$1')`  
leads to:  
" 43673771"  
(with 2 extra space characters in front coming from the spaces following the commas)

---

<div class="post-metadata">

**Author:** ![viviancels](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/bbe5ce/32.png) [@viviancels](https://community.mp3tag.de/u/viviancels)\
**Post date:** [December 11, 2022, 8:26am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/7 "2022-12-11T08:26:21Z")

</div>

Yes, mistake was in those 2 spaces after commas and before apostrophes.  
Now this works well:

```auto
$regexp(%_DIRECTORY%,'.*\(\d{4}\) (.*)','$1')

```

---

<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:** [January 10, 2023, 8:26am UTC](https://community.mp3tag.de/t/rename-folder-with/59241/8 "2023-01-10T08:26:34Z")

</div>

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