Multi disc album folder renaming action-different levels

I have created an action for renaming folders based on extension.

With this code, if extension is flac it will add bitspersample and sample rate to the folder name otherwise it add the extension like MP3 or ALAC.

%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),"("$upper(%_extension%)")" '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')

I have found that this code become not so useful for multi disc albums because of the different folder structures.

I am using a folder structure like below.
(level4) (level3)\ Level2 \Level1
mymusic\FLAC\Artist-year-Album\CD1
mymusic\FLAC\Artist-year-Album\CD2

In that folder structure above code only changes names of the CD1 and CD2 folders not Artist-year-Album this folder like below.

mymusic\FLAC\Artist-year-Album\CD1 [bitspersample-samplerate]
mymusic\FLAC\Artist-year-Album\CD2 [bitspersample-samplerate]

What I want to do is rename multi disc folders given below

mymusic\FLAC\Artist-year-Album [bitspersample-samplerate]\CD1
mymusic\FLAC\Artist-year-Album [bitspersample-samplerate]\CD2

First of all is there any way to change name of the Artist-year-Album folder given above with an action ? if yes than an if condition might be a solution for that like
if total disc is equal and greater than 2 change the name of level 2 folder otherwise change the name of level 1 etc.

whenever I run this code it create new %ARTIST%'-'%YEAR%'-'%ALBUM% folders then CD2 folders.

$ifgreater(%discnumber%,1,%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),"("$upper(%_extension%)")" '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')\CD%discnumber%,%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),"("$upper(%_extension%)")" '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')'))

I would use an absolute path and not a relative one and add the CD part in square brackets, so that this level only is inserted if the discnumber is filled.

You just have to move your part in square brackets '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']' to your "Level2".
This means BEFORE your \CD%discnumber%... part.

I would do it with two actions:
One for the single disc albums
One for the multi disc albums

'['%_bitspersample%'-'$cutRight(%_samplerate%,3)']' this part is actually before the \CD%discnumber%

%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),"("$upper(%_extension%)")" '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')

with this code first it checks whether it is FLAC or not and if it is flac then add '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']' information. if it is not flac then add the extension. I made a mistake in copy/paste in my first post. I am using the below version and works like a charm in single disc albums.

%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),'['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')

@LyricsLover is that what you mean or can you modify the code please. For your suggestion about the two seperate actions, how can it be done ? could you please explain little bit.

@ohrenkino How absolute path can be implemented to the code, I have no experience. Could you pelase explain a little bit.

Use something like
d:\mymusic\FLAC\Artist-year-Album[\CD1]

%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),'['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')

If the above expression is OK for your case, you could combine that for your two possible album variants (single/multi disc albums) with only one action and something like
$ifgreater(a,b,x,y) (From the help: if number a is greater than number b, x is returned, otherwise y.)

The y-part would be your above code.
The x-part is the one with your \CD%discnumber% code or the suggestion from @ohrenkino

@ohrenkino Is that what you mean ?
$ifgreater(%discnumber%,1, D:\mymusic\FLAC%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),"("$upper(%_extension%)")" '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')\CD%discnumber%,D:\mymusic\FLAC%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'),"("$upper(%_extension%)")" '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')') ) currently It worked but If the folder structure changes and if any new folder level is added then this might become fail. This is why I am triyng to figure out with a dynamic statement

Currently I am using your suggested function but it create a new %ARTIST%'-'%YEAR%'-'%ALBUM% (extension) folder inside %ARTIST%'-'%YEAR%'-'%ALBUM% (extension) folder then add CD1 folder
a:%discnumber%
**b:**1
x:%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'), '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')\CD%discnumber%

y: %ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'), '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')'))

The final code is :
$ifgreater(%discnumber%,1,%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'), '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')\CD%discnumber% ,*%ARTIST%'-'%YEAR%'-'%ALBUM% $if($eql(%_extension%,'FLAC'), '['%_bitspersample%'-'$cutRight(%_samplerate%,3)']','('$upper(%_extension%)')')* )

Before running the action it was:C:\Users\u\Desktop\MP3tag deneme - Kopya\Ahkmed-2003-Ahkmed (MP3)\CD2

When I run this code for three times folder path becomes below:
C:\Users\u\Desktop\MP3tag deneme - Kopya\Ahkmed-2003-Ahkmed (MP3)\Ahkmed-2003-Ahkmed (MP3)\Ahkmed-2003-Ahkmed (MP3)\CD2

I don't want to do dig into that maze of $ifs.
For what I see: you have a static part that defines how far from the root of the drive your dynamic folders start, e.g.
(a more conventional approach without all the bits and samplerates):
d:\mymusic\%albumartist%\%year% - %album%[\CD %discnumber%]`
would create folders always starting in the folder "mymusic", followed by the dynamic data for ALBUMARTIST, YEAR and ALBUM and optionally, if there is a filled DISCNUMBER, an extra folder for the separate disc.

As far as I understand your construction, the part

is the same for single and multi-disc albums so you could easily simply add the [\CD %discnumber%] to get an optional folder for the extra disc.

Also, I think that you could simplify your statement from
$if($eql(%_extension%,'FLAC'),"("$upper(%_extension%)")"
to
$if($eql(%_extension%,'FLAC'),"("FLAC")"

Yes. Your code describes a relative path, relative to the currently treated file where the current folder is the starting point in the hierarchie.
My suggestion is to use an absolute path that always uses the same starting point in the hierarchie.
The field variables will take care of the dynamic assignment.