There have been a couple of posts on this topic, e.g. here, but I thought I'd share my solution to creating a folder grouping of a certain number of letters, using the first letter of a sort field (falling back to main field if empty). This is useful for players that struggle with long lists, like in a car.
The formula produces the letter group folder name that you can include in your complete file path when doing a tag - filename action, e.g. "E:\Music\Classical\A-D\Bach, Johann Sebastian..."
I use %composer% and %composersort%, but these can be adapted to your tagging or need
If you don't need to fallback to another field in case the sort field is empty, the $if2() statements can be simplified by replacing with just your field (e.g. %artist%)
The letter group size as shown is 4, yielding 7 groups (A-D, E-H, etc). To alter, adjust the occurrences of 4 and 3 (4-1) in the formula up or down
It handles the fact that for most group sizes, the last group will be shorter than the others
It doesn't trap the fallback field being empty too
Ok, here are some more:
.audiosport
becomes 1-4
:edward
creates =-@
柳 譲治
creates
柱-Z
I do not claim that the suggested expression should cater for all these more special cases. It should become clear under which conditions it is useful to use it.
With names that are made up of letters (A..Z, a..z) as stated in the original post. It would be quite easy to extend to deal with numbers (0..9) and punctuation, but that is not a need that I have.
OK, So the (only) use case is that it works with characters in the range of alphabetic characters in the ASCII range.
It does not cater for
punctuation,
Umlauts,
accented characters,
kyrillic,
sanskrit,
japanese,
chinese,
korean
characters (even though they are also valid characters/letters in the respective written language).
Yes, it will help others if they get an idea what the suggestion does.
And for the ASCII range alphabet characters it does exactly what you have decribed and it will be a useful piece fo code for all those who have a similar use case.
I just wanted to add a word of caution for all those who might have not just exactly this use case and then might stumble over unexpected results.
I also thought that a community should seriously look at suggestions and then evaluate them. In this case, the evaluation narrowed down the more general approach to that what the script actually does. But that function is OK then, IMHO.
Please do NOT delete this. I just happened to stumble across it. I have done this manually for years. I am so glad someone found a way to do this automatically.