# Parsing a portion of current folder name to rename files

**URL:** https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812
**Category:** Support
**Created:** [April 27, 2023, 9:13am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812 "2023-04-27T09:13:15Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 9:13am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/1 "2023-04-27T09:13:16Z")

</div>

say i have a lot of folders in the uniform format of  
%artist% - yyyy-mm-dd - venue, city, state  
i.e  
Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY

with files named  
`01. %title%.flac`  
`02. %title%.flac`  
`03. %title%.flac`  
`04. %title%.flac`  
`05. %title%.flac`  
`06. %title%.flac`  
`07. %title%.flac`  
`08. %title%.flac`

the track numbers at the beginning of the filename are not tags and not in the tags AFAIK, as the tracks have discnumbers and instead of 1,2,3,4,5,6,7,8 are really disc1 1-5, and disc 2 1-3

id like to automatically parse yymmdd and rename the file from something like  
`01. Stairway to Heaven.flac`  
to  
`lz731201d1_01_Stairway_To_Heaven.flac`

if i was renaming it manually i would use  
`lz731201d%discnumber%_ $num(%track%,2)_$replace(%title%, ,_)`

im doing one band at a time so the 'lz' is easy to add to the syntax and doesnt need to be parsed. but i need to automatically parse the yymmdd for multiple folders

how would one do that?

thanks!

---

<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: [April 27, 2023, 9:19am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/2 "2023-04-27T09:19:08Z")

</div>

> [@jerryfreak](#):
>
> for some reason the post is getting autoformatted

See here for some hints on how to post strings as they are:

> [@Hints for asking Support Requests](https://community.mp3tag.de/t/hints-for-asking-support-requests/56190):
>
> If you need support using Mp3tag, you can help the community members that are about to support you in finding a solution or workaround to your problem, by following these simple guidelines. Be descriptive, also in what you’ve already tried Please give a short explanation what’s not working as expected or what you’re trying to achieve. It’s best to know any details about the problem at hand and especially, what steps you’ve already tried to solve it by yourself. Helpful information also includ…

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 9:24am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/3 "2023-04-27T09:24:46Z")

</div>

fixed the code thanks

---

<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: [April 27, 2023, 9:27am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/4 "2023-04-27T09:27:34Z")

</div>

To get the first part extracted, you could try:  
`$regexp('Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY',^(.).*? (.).*? - \d\d(\d\d)-(\d\d)-(\d\d) - .*,$1$2_$3$4$5)`  
which lead to:  
"LZ\_731201"

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 9:29am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/5 "2023-04-27T09:29:59Z")

</div>

but im not trying to do a single folder im trying to parse from folders in same format, like  
Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY  
Led Zeppelin - 1973-12-04 - Knickerbocker Arena, Albany, NY  
Led Zeppelin - 1973-12-07 - Spectrum, Philadelphia, PA  
Led Zeppelin - 1973-12-09 - Boston Garden, Boston, MA

and then ill have to do

Boston - 1974-02-01 - Madison Square Garden, New York, NY  
Boston - 1974-02-04 - Knickerbocker Arena, Albany, NY  
Boston - 1974-02-07 - Spectrum, Philadelphia, PA  
Boston - 1974-02-09 - Boston Garden, Boston, MA

etc.

again they are in uniform format but some artists have one word names, some have four or more word names

---

<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: [April 27, 2023, 9:36am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/6 "2023-04-27T09:36:14Z")

</div>

To get just the date, try  
`$regexp('Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY',^.*? - \d\d(\d\d)-(\d\d)-(\d\d) - .*,$1$2$3)`

To get just the date, try  
`$regexp('Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY',^.*? - \d\d(\d\d)-(\d\d)-(\d\d) - .*,$1$2$3)`

> [@jerryfreak](#):
>
> again they are in uniform format

No, they are not as they have different patterns to generate the initials  
So there are different band names - I would have filtered for those that match the two-part names and then apply the expression anyway as that would automate a fair number of entries.

Then you could modify the expression and the filter to cater for just 1 part names and then treat the next batch... but that is up to you.

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 9:43am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/7 "2023-04-27T09:43:15Z")

</div>

i dont need to generate the initials, can type them in myself as i will run the script forhundreds of folders for one artist at a time. ideally i want it to ignore everything in the folder name and just parse the date

if its easier i could bulk edit the folder names and take the artist out and add it back later so the folders just begin with dates

---

<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: [April 27, 2023, 9:44am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/8 "2023-04-27T09:44:55Z")

</div>

Have tried my suggestion

> [@ohrenkino](#):
>
> To get just the date, try  
> `$regexp('Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY',^.*? - \d\d(\d\d)-(\d\d)-(\d\d) - .*,$1$2$3)`

Instead of the real string, insert %\_directory%:  
`$regexp(%_directory%,^.*? - \d\d(\d\d)-(\d\d)-(\d\d) - .*,$1$2$3)`

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 9:49am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/9 "2023-04-27T09:49:00Z")

</div>

in which converter do i enter the above expression? nothing works when i put it in 'tag\>filename' or 'filename\>filename' (the latter of which requires two fields)

---

<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: [April 27, 2023, 9:50am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/10 "2023-04-27T09:50:02Z")

</div>

> [@jerryfreak](#):
>
> nothing works when i put it in 'tag filename' or '

Could you post a screendump - as that would be the right place.

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 10:04am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/11 "2023-04-27T10:04:37Z")

</div>

i fixed your syntax from 'driectory' to 'directory' and its now parsing the folder name within tag\>filename converter,  
normally i would use tag\>filename converter and enter  
`lz731201d%discnumber%_$num(%track%,2)_$replace(%title%, ,_)`

replacing lz731201 with  
`$regexp(%_directory%,^.*? - \d\d(\d\d)-(\d\d)-(\d\d) - .*,$1$2$3)` returns the entire foldername and doesnt parse the date

i could probably bulk edit the folders to

731201 - Madison Square Garden, New York, NY

to avoid the extra formatting

---

<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: [April 27, 2023, 10:16am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/12 "2023-04-27T10:16:24Z")

</div>

Screendumps would tell so much more.  
I am completely lost to what you do, which data can be found where and, given the exmple strings for folder names, I cannot reproduce that

> [@jerryfreak](#):
>
> the entire foldername

is returned. Is this a differently structured folder name?  
`^.*? - \d\d(\d\d)-(\d\d)-(\d\d) - .*,$1$2$3)`  
works with  
Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY  
as well as  
Boston - 1974-02-09 - Boston Garden, Boston, MA

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 10:34am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/13 "2023-04-27T10:34:58Z")

</div>

oops sorry, my mistake, the folders were  
Led Zeppelin - 1973-12-01 Madison Square Garden, New York, NY  
not  
Led Zeppelin - 1973-12-01 - Madison Square Garden, New York, NY

seems to be working now, am testing with different artists

one more question, kind of an aside is there an easy way to bulk rename folders from

Artist - DD\_MM\_YY Venue, City, State  
to  
Artist - YYYY\_MM\_DD Venue City state

doesnt need to be in mp3tag, perhaps theres a linux or windows script that would do it easily

i can do it in a few steps using mp3tag and bulk rename in ubuntu but there is probably an easier way. the old folder names are terrible because they dont sort chronologically

thanks so much!

---

<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: [April 27, 2023, 10:42am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/14 "2023-04-27T10:42:31Z")

</div>

Try another regular expression for \_DIRECTORY:  
`$regexp('Artist - 01_02_20 Venue, City, State',(.*) - (\d+)_(\d+)_(\d+) (.*),$1 - $4_$3_$2 $5)`

Use either Convert\>Tag-Tag or an action of the type "Format value".  
I wonder where 2 extra digits for the YY should come from.

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 10:56am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/15 "2023-04-27T10:56:45Z")

</div>

> [@ohrenkino](#):
>
> $regexp('Artist - 01\_02\_20 Venue, City, State',(._) - (\d+)(\d+)(\d+) (._),$1 - $4\_$3\_$2 $5)

tried that expression in 'format value' and it copied files from  
"Boston - 01\_01\_11 Madison Square Garden, New York, NY"  
to  
"Artist - 20\_02\_01 Venue, City, State"

---

<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: [April 27, 2023, 10:59am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/16 "2023-04-27T10:59:28Z")

</div>

I think by now you should be able to adapt such an expression and replace the test string with the source variable.

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 27, 2023, 11:04am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/17 "2023-04-27T11:04:55Z")

</div>

yes thanks! this worked great for YYYY beginning with 20YY  
$regexp(%_directory%,(.\*) - (\d+)_(\d+)\_(\d+) (.\*),$1 - 20$4-$3-$2 $5)

ill have to do 20th and 21st century dates in two batches, but thats fine

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [April 28, 2023, 6:04pm UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/18 "2023-04-28T18:04:51Z")

</div>

actual final script for file renaming

`$regexp(%_directory%,(.*) - (\d+)_(\d+)_(\d+) (.*),$1 - 20$4-$2-$3 $5)`

note that the 2 and 3 are switched from your originally suggested expression, to yield YYYY-MM-DD

---

<div class="post-metadata">

### Author: ![jerryfreak](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/85f322/32.png) [@jerryfreak](https://community.mp3tag.de/u/jerryfreak)
#### Post date: [May 4, 2023, 11:25am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/19 "2023-05-04T11:25:55Z")

</div>

i just installed mp3tag on ubuntu under wine to use the same scripts above that were working successfully under windows

the file rename (convert\>tag-filename) works fine, but the folder rename (quick action\>format value\>\_directory) will not work

perhaps a permissions issue?

---

<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: [May 4, 2023, 11:46am UTC](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812/20 "2023-05-04T11:46:10Z")

</div>

> [@jerryfreak](#):
>
> perhaps a permissions issue?

if you suspect a permission issue then you are the only one to check and test whether changes improve things.

[Next page](https://community.mp3tag.de/t/parsing-a-portion-of-current-folder-name-to-rename-files/60812.md?page=2)
