_DIRECTORY regular expression

Can't work this one out. I'm trying to remove leading "The " from every folder in the path.

So, I have e:<u>The Beatles\The Beatles [Disc 1]\01-back in the ussr.m4a etc

If I right-click the top folder (underlined above), enter mp3tag, and run my action...

Replace with regular expression
Regular expression: ^The\s+
Replace matches with: (i.e. nothing)

...I end up with...
e:\The Beatles\Beatles [Disc 1]\01-back in the ussr.m4a

...but I want...
e:\Beatles\Beatles [Disc 1]\01-back in the ussr.m4a

...am I missing something? Thanks

_DIRECTORY only refers to the directory where the audio files are in.

Ah, I see. Is there something I can use instead that will produce the effect I'm after? If not, can I file a request?! Thanks!

Answering your own post - the first sign of madness? :smiley:

I don't think I can do what I need using mp3tag (ie run a replace with reg ex on all folders in the path, not just the one that contains the audio files) so I found this freeware utility which does batch file/folder renaming and can use regular expressions. Thought I'd post a link in case anyone has a similar query in future....


Formatstring: $regexp(%_folderpath%,The\s,)%_filename%


Thanks, but that removes every instance of "The", whereas I only want to remove leading "The " from the beginning of a folder name. I tried $regexp(%_folderpath%,^The\s,)%_filename% but that doesn't work. Plus, I'd like to be able to run this as part of my actions, and I can't work out how to do a tag>filename as a user-defined action?

Ah, I can create an action, sorry...

Format Value
Format string: $regexp(%_folderpath%,The\s,)%_filename%

...but I can't work out how to tell it to only remove "The" when it occurs at the beginning of a folder. Can anyone point me to this? Normally ^ is used for beginning of line, isn't it?



Ah, thanks so much! I'd never have got that in a million years! I'm off to read up on regular expressions some more!! Thanks again!

Ah, I spoke too soon. This regex works, but creates a new folder structure with leading The removed. I'd like to keep the folders and files where they are, just remove the leading The.

According to C:/Program%20Files/Mp3tag/help/options_converter.html#ttf "You can mark directories via the backslash within the format string. Please note that Mp3tag won't rename directories but will create new directories below the current working directory if you use backslashes within the new filename pattern." - which as I read it means I'm out of luck, I think?

There is a simple short version too:


Hmm, I don't think so ... the only thing that will make some trouble is ... how many other non music files are left in the old folder structure, which you have to move manually into the new (renamed) folders?

The forum contains an interesting thread about some experimental method to move non music files by Mp3tag:
Cover mit verschieben


All files in all folders are music only - my problem is, I don't want to create a new set of folders with this regular expression, I want to rename the existing ones without creating new folders and/or moving files.

Doing it this way means I'm left with the old, empty, folders which I need to delete manually, which defeats the point of trying to create this action to automate things!

I think what I need is to be able to create...

Action: Replace with regular expression
Regular expression: ^The\s
Replace matches with: (i.e. nothing)

...and of course my problem is that _FOLDERPATH is not an available Field!

This small hta script removes empty folders.
pcwEmptyFolder.zip (2.52 KB)

So you think Mp3tag should have find some smart way to detect if a folder in a (renamed restructured) folderpath does exist and then rename it, and if not, create new folder and hook it into the foldertree and move all files from old folder to new folder and remove old folder if empty?
Sounds rather heavy to me.


pcwEmptyFolder.zip (2.52 KB)

Well, no!


Action: Replace with regular expression
Regular expression: ^The\s
Replace matches with: (i.e. nothing)

...simply renames the folder containing the music files. If I right-clicked on a folder called E:\music\the beatles\the beatles [disc 1] to launch mp3tag it's reasonable for an action to be able to affect all folders in that specific path. Doesn't need any logic, really, it's just a rename.

I'm not talking about file moving, simply a rename of an existing folder, in the path that the user would enter.

How to address one folder in the folderpath from the view of the file?
For now Mp3tag provides two system meta tag fields:

I could think of something like this to read folder names:
$folder(-1) (same as %_parent_directory%)
$folder(0) (same as %_directory%)

Or simply use positive numbers:
0 the folder where the music file resides
1 one folder up
2 two folders up
and so on.

Adding an optional parameter can rename a folder name:
$folder(n,'new name')


For completeness, here's my workaround. So, I run this action...

Format Value
Format string: $regexp(%_folderpath%,\\The\s,)%_filename%

...which creates new folder structure without leading "The ", leaving the old empty folders behind.

I've created a .bat file in C:\Program Files and set it to run as a scheduled task overnight, just after the one that wakes the PC to do my overnight housekeeping (Windoze updates etc). .bat file contains....

@echo off

CD /D C:\documents and settings\username\my music\itunes music\blah blah
for /f "delims=" %%i in ('dir /s /b /ad ^| sort /r') do rd "%%i">NUL

CD /D C:\documents and settings\username\my music\itunes music\blah blah
for /f "delims=" %%i in ('dir /s /b /ad ^| sort /r') do rd "%%i">NUL

CD /D C:\documents and settings\username\my music\itunes music\blah blah
for /f "delims=" %%i in ('dir /s /b /ad ^| sort /r') do rd "%%i">NUL

...out of paranoia I've set three lines in this batch file to target the three specific folders that contain my music - this batch would work higher-up the folder chain and do it all in one go (it won't delete folders with anything in them, natch) but I'd rather avoid touching the ludicriously complex set of folders that iTunes uses for Album Artwork, just in case. Not fatal if they're deleted, but an iTunes artwork scan takes a while on my library!

Another advantage of doing this as a .bat file is that I can set it to run as a Tool in mp3tag, so I can double-click or right-click my music files and run it.

Code came from here... http://blogs.msdn.com/oldnewthing/archive/...17/8399914.aspx

@DetlevD - huge thanks for the regex code!

For completeness, here's my workaround
for completeness I'd recommend to have a look at a renamer tool like ReNamer ...

HTH, andreas

Thanks Andreas - I like my batch file idea, means I can run it from mp3tag. But that renamer will certainly come in useful, thanks!