Sorting in different folders by file type

I would like to sort my music by Extension, Artist, Album, Track. So I have a MP3, Wav, M4A and so on root folders then Artist, Album, Track.

I would like each file to be renamed, Artist, Album, track when it is moved.

Would someone mind writing a script for this I would greatly appreciate it.
Thanks in advance
Tom

That’s pretty much the default script. So the default will give you albumartist/album/tracknumber tracktitle

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

It will also add the discnumber if it is more than one. It has some other specialities, such as creating the album folder only if there is an album artist, and setting the artist name in front of the track title if the album contains tracks from different artists. If you don’t want this all and really just albumartist/album/tracktitle then you could reduce it to:

$if2(%albumartist%,%artist%)/%album%/%title%

Nice and simple. Now for the file extension there is a variable %_extension%. To have a folder with the extension name just add it to the beginning of the script separated by a slash for the folder separator:

%_extension%/$if2(%albumartist%,%artist%)/%album%/%title%
3 Likes

For consistency, I would probably write this as:

$upper(%_extension%)/$if2(%albumartist%,%artist%)/%album%/%title%

to avoid potentially creating multiple directories on case-sensitive file systems.

3 Likes

Thank you both. At the moment I have a greater problem. The program crashes often. With the default script.

Can you be more specific when exactly it is crashing?

We are also preparing the next release of Picard and have fixed a couple of potential crashes there. I have uploaded a current development build on:

https://s3.eu-central-1.amazonaws.com/artifacts.picard.uploadedlobster.com/picard-setup-2.5.0.dev2.exe

Could you check whether this solved your issue?

If this does not solve you issue, could you report details on a crash by running Picard from command line with the “-d” command line option, make the application crash and post the output on the command line here?

If you are on Windows, make sure you have installed Picard using the installer. Then open a Windows command prompt and start Picard with:

"C:\Program Files\MusicBrainz Picard\picard.exe" -d

It would be great if we could address the crash your experience in time for the next release.

1 Like

I will gladly. However my personal time is very limited. It is why I didn’t sit learn the script language. It may be a few days before I can post again.

Tom

1 Like

I apologize if this is covered somewhere and I missed it. I’m using your script and would like to have it sort output so for an album with multiple file types they sort into separate folders. When I run your script it lumps all the tracks into one folder by album name.

my desired output would be

artist/album/flac/ (all flac files for that album)
artist/album/mp3/ (all mp3 files for that album)

This is primarily to easily separate the mp3. I would also be okay with a sort that split collection to:

Flac/artist/album/tracks
MP3/artist/album/tracks

MP3 files are used for mobile devices only. Which allows separate collection. Thanks

The %_extension% variable used in the script is supposed to hold the file extension and is used in the above scripts to create separate folders. Can you maybe share the exact script you are using?

1 Like

I’m using RDSwift’s script. I ran it on a test folder that has both the flac and mp3 together. It saved to folder for album name. I imagine an if statement will allow the output if the %_extension% variable can properly detect the file type. I looked through the script briefly and can look closer later on to see if there is a place to logically put such an “if” … Thanks

If you’re talking about the script in my GitHub repo, then you should be able to maintain separate paths for each format by changing Line 446 to:

$rreplace($upper(%_extension%)/%_nFilePath%/%_nFileName%,[?*:\\_]+,_)

Note that I haven’t tested this, but it should work (or at least point you in the right direction).

yes that is the script. I will give this a try. Thanks!

Unfortunately same result dropped it into one folder for the album. I will dig into this later on and let you know if I get it figured out.

That’s odd because it should have created a new full path beginning with the file extension in upper case (with the initial and other stuff below that).

Alternately, you could try adding a new line after Line 411 containing:

$set(_nFilePath,%_nFilePath%/$upper(%_extension%))

This should create the different extension directories under the album directory.

Unfortunately it still dropped into one folder not setting up a sub folder or different folder for file type. I will look at this tonight. I really appreciate your response. It may well be error on my end.

I updated the script on my repo to include an option to put the files in extension-specific subdirectories under the album directory. It definitely works because I tested it here. To enable this option, you need to change Line 87 of the updated script from:

$set(_aExtension,)

to:

$set(_aExtension,1)
2 Likes

Do you have “move files” enabled?

2 Likes

Perfect, amazing that you did the change to your script.

1 Like

Thanks for letting us know that it worked for you. As for the change, it was pretty minor, and perhaps there are others that can use it.

1 Like

I hate to be a pain one last question related to the output as it moves the files. Is it possible to have the artist listed by first name?

Example: ~ R ~\Reba McEntire {date} album title\ …
I tried getting it to sort artist by first but I was either in the wrong part of your script or just didn’t get the parameters correct. It would also be helpful to have option for “the” (“The Rolling Stones” … “Rolling Stones”, The … ignore “the” - “Rolling Stones”. I know that dropping “the” is not technically correct.

I did but I realized later I made an error and probably didn’t save the change - very difficult day with medical news for my sister and I shouldn’t have been trying to sort this at same time. I suspect his original answer would have worked without need to amend the script as he did.