Moving files and their containing directory untouched

Hello Brainz,
I am new to this program, project, and community, so please forgive me if I am asking a question that has already been answered.

I am looking to search a folder, with albums in folders, and sort by the tagged artist/albumartist/album/genre (mainly genre). This has worked marvelously. I have figured out how to move the audio files to a specified directory, and I use the wildcard string *.* to move all additional files within the source folder. I have removed everything from the “Name Files like this” field, which has allowed me to achieve moving without renaming/retagging the files. This is headed exactly where I want to be.

I seek to have the source folder moved also, without any renaming of the directory. So, instead of my target directory containing just the selected audio and additional files, it will contain the source directory, with the files inside. I see there is an option to delete empty directory, but I just want it moved.

I feel like there is a way to do this by adding something to the “Name files like this” field, but I scoured the functions and cant seem to find anything relevant. Nor do I know that I would be able to use the proper syntax.

Thank you in advance for any information you could provide to help me achieve this!!

I have discovered using %_dirname%/ creates a directory. However, it is using the full file path instead of just the name of the containing folder. If I could find a way to truncate the full path, I will be 100%. I feel like this is so simple, and it’s staring me right in the face. Thank you again for any assistance.

I have attempted to use the $truncate(,) action with the %_dirname% variable. I have determined that I need to remove 37 characters from the beginning of the new target directories. I can’t seem to get it to just indiscriminately truncate a specified amount of characters.

/%genre%/$truncate(%_dirname%,-37)/ - This truncates the new directory 37 characters from the end.

/%genre%/$truncate(%_dirname%,37)/ - this truncates the new directory from the first 37 characters to the end.

I just can’t seem to get it to eliminate the first 37 characters in the directory name. I am currently batch renaming the files after saving with a program that allows me to remove the specified characters.

Please HELP!!! :smile:

Have you got this page?
https://picard-docs.musicbrainz.org/en/functions/list_by_type.html

“truncate” sounds like it will operate from the wrong side. So what about $right ? Just do the maths to grabthe length of your filename.

Sorry, I don’t do MB scripting, but this thread is too quiet. :smiley: There are more elegant ways to do this.

1 Like

Welcome. I’m a bit lost understanding what exactly you try to achieve, can you give an example of file paths you have and what you want to get in the end?

Usually how renaming directories works in Picard is that you setup the base directory where you want you music files to go, enabled “move files” and setup the scripting to name the folders according to your wishes. So e.g. the default file naming script is:

$if2(%albumartist%,%artist%)/
$if(%albumartist%,%album%/,)
$if($gt(%totaldiscs%,1),$if($gt(%totaldiscs%,9),$num(%discnumber%,2),%discnumber%)-,)$if($and(%albumartist%,%tracknumber%),$num(%tracknumber%,2) ,)$if(%_multiartist%,%artist% - ,)%title%

This will create a folder hierarchy for album artist / album name.

If you want to keep the names of the files just disable “Rename files” in options.

3 Likes

My apologies for being unclear, while trying to explain in detail, without providing specific examples. So, I have a large collection, which is spread across daily dated folders, with folders that contain mp3 and other files. I am trying to list my collection so I can separate genres that I like, to specific genre folder so I can remove the ones that I do not. I want to preserve everything, including the source album folder name, without renaming to an artistname-artistalbum format. But, when saving the files using the %_dirname% variable… it creates the directory when saving to the target dir, however the folder it creates includes the entire file path. So each folder created has a plethora of unwanted characters. I will give an example:

if the album is located at:

/mnt/sdb/mp3/year-month/date/Music_Makers-Name_Of_Their_Album-YEAR-GRP/

When the save process is completed, the newly created directory at the specified target location show as follows:

_mnt_sdb_mp3_year-month_date_Music_Makers-Name_Of_Their_Album-YEAR-GRP/

I wish to have just the dirname Music_Makers-Name_Of_Their_Album-YEAR-GRP/ created.

I have determined that it is the first 37 characters that need to be removed from the new directory. The issue I cant get past is each function I have tried, and looked at, all require a text string. So, with the parent directories being dated, and different, I am not sure of what text string I could supply.

SO curently, after completing the file save, I have to go to the target directory with a batch renaming tool to specifically remove the first 37 characters from each newly created folder.

1 Like

Now I see, thanks for giving the examples. This one is interesting, I haven’t seen %_dirname% discussed here much. In theory it is exactly for a use case like yours. In practice it obviously is not very useful, as it already has the directory separators all replaced by underscores (like it is done for all variables, to avoid causing e.g. %artist% being “AC/DC” to create subfolders), and also because the variable contains the full path.

But in your case where you know the exact length of the base folder you should be able to truncate the variable accordingly with $substr:

$substr(%_dirname%,37)/

Maybe to better support such cases Picard should have some functions for directory handling. E.g. a function $parentdir() which just gives the name of the directory containing the files (“Music_Makers-Name_Of_Their_Album-YEAR-GRP/” in your case).

It could also allow to specify how many levels up it should include, let’s say $parentdir(3) would in your case give “year-month/date/Music_Makers-Name_Of_Their_Album-YEAR-GRP/”.

5 Likes

I tried the suggested command and it keeps giving me the same results as truncate. It is removing the characters from the end of the folder name, thus effectively removing the characters I desire to keep. I have only tried a few variations of the command. I think the issue I am facing is not supplying the correct “text” string to process from. I have little time before work today so I will attempt other options tonight. Thank you for pointing me in the right direction.

And I agree that the $parentdir() variable is exactly what I would need to do this with ease. Fingers crossed for adding this in a future release.

I feel like the underscores could be the key. if I could remove from the first to the eighth underscore, including all characters between, this would leave me with just the directory I want. I apologize that my scripting/coding skills are novice at best.

That shouldn’t happen, $substr(%_dirname%,37) definitely should give you the results from 38th character till the end. Are you sure you did not accidentally get another comma in there? $substr(%_dirname%,,37) would be the same as $substr(%_dirname%,0,37) and would give the first 37 characters starting at the beginning.

If that’s not the solution to the issue, please share your full renaming script here and I’ll try to figure out what’s going wrong.

2 Likes

When I attempt to use $substr(%_dirname%,37) the options panel will not let me save the settings. It tells me that $substr() requires 3 arguments. So yes to satisfy this error I did use ,0,37 when I tested earlier today. The script is simple…

/%genre%/$substr(%_dirname%,0,37)/

Reading the documentation, I understand how the 3rd argument is throwing this off, I just don’t know how to get it right. It even provides an example that only has 2 arguments:

$substr(abcdefg,-3) ==> “efg”

I feel like this is the example for my use case, which would make my string:
/%genre%/$substr(%_dirname%,-37)/

So ultimately I cannot save the settings without supplying 3 arguments to the $substr() function. I feel silly that I cannot achieve something so simple considering the complexity that is possible through this program.

Once again I want to thank you for assisting me so diligently.

EUREKA!!!

I just tinkered a bit and found that putting a comma after the numerical argument has corrected the issue! So using the following string works perfectly. It creates the genre folder, and strips the extra file path from the directory!!!:

/%genre%/$substr(%_dirname%,37,)/

Not sure if this would constitute correcting the documentation, but I see no reference in the examples to putting the comma afterwards to satisfy the requirement for 3 arguments.

This was interesting. With that being said, I will continue to express extreme gratitude to everyone who makes up the open source community!

3 Likes

Oh yes, I forgot, but the third parameter was made optional in version 2.8 of Picard. So you are using an older version and there $substr(%_dirname%,37,) is the correct syntax. But glad to hear it’s working for you now :slight_smile:

2 Likes

I failed to mention that I am using Linux Debian-Bullseye. I did not look into the version that I am using. If the latest release in the repository is an older version, I will attempt to compile the latest version for my architecture.

I just checked and I am using version 2.5.6-1 from the Debian bullseye repo. I have noticed that debian tends to get the newer versions later than other platforms.

Not really, just depending on the point of view it gets newer versions never or rather quickly :slight_smile: Part of the Debian philosophy is to keep a certain release stable, so on the stable release the repositories don’t receive updates that change functionality, only important bugfixes. So current Debian stable “Bullseye” has Picard 2.5.6 in the repositories, and this won’t change.

On Debian testing on the other hand you usually find the very latest version of the packages. The picard package on testing usually receives an update shortly after we have released a new version.

If you want to use a newer version of Picard on Debian stable you have a few options. You can install Picard yourself from source of course. You could also try out the generic Flatpak package (also Snap, but if you have the choice I’d recommend the Flatpak one). The packages we provide our self for Ubuntu might also work for Debian, see the Ubuntu PPA links on Picard downloads, but I haven’t tested it. Another option is to install it via Python 3 pip, you just don’t get the desktop icon then by default and UI translations are currently not working that way.

3 Likes

Do you recommend flatpak over snap for security reasons? (snap has been catching some heat lately) I may be able to force a later or what they consider unstable/testing build through apt. I think I may go the pip3 route first, but nonetheless… You have been exceptional with the information you have provided me.

Well this new version is wonderful. The script naming preview is clutch! Troubleshooting 101, make sure you are using the latest version!

4 Likes

Nothing big really, but Flatpak is more flexible and you can allow the sandbox to access additional folders (in addition to the home folder, which is accessible by default). Also the Flatpak version in general made much less trouble in the past and I have some personal preference of Flatpak over Snap :person_shrugging: But apart from this both versions work. I’m currently maintaining the Snap version myself. So I know it’s functional, but nevertheless personally prefer Flatpak :smiley:

2 Likes