Fully qualified versus relative path in format string

I'm trying to move files to folders based on artist and album names but the new filename is always relative to the current file location and not a fully qualified path from the root of the drive. Assuming that files will be moved from and to the same drive is acceptable. My file structure is:

\
.....My Music\
..........Album Artist 1\
...............(Year) Album A\
....................Track - Title.mp3
..........John E. Guitarplayer\
...............(2023) Hit Songs\
....................001 - Happy Song.mp3
..........Album Artist 3\
...............(Year) Album C\
....................Track - Title.mp3
..........Unsorted Tracks\
...............Title.mp3
..........Other files\
...............New Music Files\
....................Target File.mp3

I use mp3tag to load correct tag information then use a format string to rename and move the files to appropriate folders:

Current Directory: G:\My Music\Other Files\New Music Files
File: Target File.mp3
AlbumArtist: John E. Guitarplayer
Year: 2023
Album: Hit Songs
Track: 002
Title: Sad Song

\My Music%albumartist%(%year%) %album%$num(%track%,3) - %title%

I'm expecting to get:

\
.....My Music\
..........John E. Guitarplayer\
...............(2023) Hit Songs\
....................001 - Happy Song.mp3
....................002 - Sad Song.mp3
..........Other files\
...............New Music Files\

Instead, I get:

\
.....My Music\
..........John E. Guitarplayer\
...............(2023) Hit Songs\
....................001 - Happy Song.mp3
..........Other files\
...............New Music Files\
....................My Music\
.........................John E. Guitarplayer\
..............................(2023) Hit Songs\
...................................002 - Sad Song.mp3

A new path is created in the original folder even though my format string begins with a backslash. It works the same with or without the leading backslash.

This works fine if I specify the drive letter:

G:\My Music%albumartist%(%year%) %album%$num(%track%,3) - %title%

But I can't be sure what letter Windows might assign each time I mount a removeable drive. Is there a way to reference the "current drive" in a format string?

This also works but I'd have to assume I'd never be more than 10 levels deep in the file structure:

....................\My Music%albumartist%(%year%) %album%$num(%track%,3) - %title%

It's not very elegant but gets the job done until I find myself 11 or more levels deep. Then, God knows where the file may be relocated to. Is there a better way to handle this?

You could retrieve that letter plus the colon with
$left(%_path%,2)

That works. Thanks. I guess there's no way to just refer to the root of the current drive?

Show me a way with OS means or the command line syntax and that would be the solution.
I wonder why that short piece of scripting isn't fit for your special requirements.
BTW: if you assign a drive letter manually, then Windows usually remembers that. It should be a letter that is usually not reached by the automatic drive letter assignment, e.g. J would be a letter that is probably not used by USB devices.
So your external drive should be registered by its hardware identifier and then always get the same drive letter.

That code does work. I was just thinking in terms of the commands mkdir, chdir and rmdir and how the leading backslash on a directory name determines where the action occurs. No matter where I am on a drive, the command

md \newfolder

will create a new directory named newfolder in the root of the drive while

md newfolder

will create a new directory IN the current directory. I don't know how that relates to the scripting engine in mp3tag but that's where I was coming from. $left(%_path%,2) works fine and I've already added it to my format strings. So thanks again for that.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.