Renaming a single file to include directory renames or moves subdirectories in same folder

Win10x64
MP3Tag 3.28 x64

I start with my albumartist folder, which in this case contains one album in a subfolder, and two singles:
E:\Music\Allman Brothers Band[1972] Eat A Peach [MP3]
E:\Music\Allman Brothers Band\Allman Brothers Band - Jessica.mp3
E:\Music\Allman Brothers Band\Allman Brothers Band -
Midnight Rider.mp3

I run my "Rename Standard" action group, which consists of two operations:
Format value "_FILENAME"
%artist% - %album% - $num(%track%,2) - %title%
Format value "_DIRECTORY"
E:\Music\%albumartist%\'['%year%']' %album% '['$upper(%_extension%)']'\

When I run this on the files already in the album subfolder, I get the expected/desired result. However, when I run it on either of the two single files, alone, it moves all other files in the main folder to a folder with the album of the selected file

What I want is for it to create an album folder for the single file and move the single file to that new folder, and ignore the other files/folders:

I suspect there's some logic in the action that I'm not fully understanding, but I'm not sure what/where it is. I am not understanding why the operations are applied to files/folders that are not selected. It seems they should be ignored.

You could try this:
If you only want to apply such a change to a single file you can use the Convert Tag-Filename with your format string.

Thanks. If I do that using the syntax in my first operation, will rename the file, but won't put it in a folder of course. If I subsequently run a second Tag>Filename with the syntax in the second operation, I get similarly unexpected results. So it seems like there's something in that second operation, whether it's incorrect syntax or misunderstood logic, that's throwing me.

If you see the file system from the point of view of a single file, then it sees its own filename - which can be set - and the current folder name - which can also be set.
If you set the folder name then the new name applies to all files and subfolders in that folder.
In your case you have different "current folders".
"Jessica" has the current folder

Whereas "Melissa" has as current folder

It would be up to you apply renaming patterns only to files that have the same folder depth or rename only files but not folders

OK, thanks. I think I get it. I'm not (strictly) adding folders, I'm renaming folders

If you set the folder name then the new name applies to all files and subfolders in that folder.

If I'm understanding correctly, then this is what happens:

  1. I start in E:\Music\Allman Brothers Band and I rename Allman Brothers Band - Brothers and Sisters - 02 - Jessica.mp3 to include the folder path.
  2. Mp3tag doesn't create a new folder called [1973] Brothers and Sisters [MP3] in that folder.
  3. Instead, it cuts everything in E:\Music\Allman Brothers Band, creates a new folder called E:\Music\Allman Brothers Band\[1973] Brothers and Sisters [MP3] as instructed by the syntax in my second operation, and pastes everything into that new folder
  4. It does it this way to ensure files are not lost during the renaming/moving/folder creation process (however you want to call that)
  5. This gives me my desired result - [1973] Brothers and Sisters [MP3] is now a folder under E:\Music\Allman Brothers Band and it contains the selected song, but also an undesired result where I've moved the rest of the contents of the main folder into that same new folder.

Is that correct?

It would be up to you apply renaming patterns only to files that have the same folder depth or rename only files but not folders

So this sounds like there may not be a way to programmatically rename to include folders files that are adjacent to folders. I would need to create the folder manually to get the files to the same folder depth, maybe with a dummy name (e.g. New Folder) for ease, and then apply my Rename Standard action. Is that right?

If you get all the files that you want to treat to the same folder level then you are fine.
Otherwise it is better to rename only files (possibly with an absolute path) but you may be left with empty folders as the files are moved to a different location. There are tools to delete empty folders.