Filling in the Year field


So, I've decided to dig in and automate as much of my regular tagging routine as possible through the Actions system, but this is where I've hit a bit of a snag:

I'm trying to add an action to fill/format the year field if necessary.
If year is set to four digits, I want to keep the tag.
If it is set to something longer (such as 2007-07-37) I want to just keep the first four chars
If it's blank, I want to guess the year based off the name of the directory the file is in.

What I've got so far is

$if(%year%, $left(%year%,4), <???>)

What I'm missing is the <???> bit where I WANT to have [12]\d{3} from %_directory%
Anyone see how I can make this happen? =)


Please give an example of a real %_directory% contents. And tell us which data you want to cut from it.

PS: just a personal footnote:
How often does this happen that the year is not filled but can be found in the folder name? I'd say: once in the lifetime of a track. So is it worth it to have an action of its own instead of using a simple filter (%year% MISSING) and then a converter statement that shows the probable outcome?
The other question I cannot solve: how come that the folder has the correct year but the file has not? Usually I tag the files first and then create a folder structure so the file has always the correct year, the folder might not ...


I can't find any instances right now of albums missing the year field but it does happen once in a while. The format of %_directory% could vary greatly, which is why I want to use a regular expression to extract any four digit sequence starting with a 1 or a 2 (1xxx or 2xxx).


The reason why I ask: you gave as example

which has the backslash in it - which is usually part of a pathname. So it looks to me as though it is not a plain _DIRECTORY variable.
If you wand to extract a substring from a variable you can use one of the functions $left, $right or $mid. And to find a certain character you can use the $strstr function.
As this will lead to a rather longish term I still suggest that you do it with a filter and the converter Filename -Tag and something like
%dummy% - %year%\%dummy%.