Renaming directories with metadata and technical data

Hi there,
I discovered this program a couple of days ago because I was trying to figure out which album I had in my hands, so I asked Gemini. I then downloaded and installed Picard.

I’m slowly discovering its potential and how much time it can save me with its file and folder renaming system.

I have folders containing music files, especially FLAC and WAV, which are named as follows:

artist name – title

Now, my goal would be to have all folders named like this:

artist name – title – (year) – file format – bit depth-frequency – catalog number – record label

For example:

Cirque du Soleil – Amaluna

Should become:

Cirque du Soleil - Amaluna (2012) FLAC 16-44 CDSMCD_10046_2 Cirque du Soleil Musique

Gemini suggested this script to me:

$set(\_year,$left($if2(%originaldate%,%date%),4))

$set(\_format,$upper(%\_extension%))

$set(\_freq,$if2($replace($div(%\_samplerate%,1000),.1,),‘?’))

$set(\_audio,$if2(%\_bitdepth%,‘?’)-$if2(%\_freq%,‘?’))

$set(\_catno,$if2(%catalognumber%,‘?’))

$set(\_label,$if2(%label%,‘?’))

$if2(%albumartist%,%artist%)

\- %album% \\(%\_year%\\) %\_format% %\_audio% %\_catno%

%\_label%/$num(%tracknumber%,2) - %title%

This only works if the files are moved and copied to another folder.

The problem is that the result is as follows:

Cirque du Soleil - Amaluna (2012) FLAC ‘_’-‘_’ CDSMCD 10046-2 Cirque du Soleil Musique

Instead of the bit depth and sampling frequency, it shows: ‘_’-‘_’

I tried enabling some plugins but didn’t get any results.

Could you please help me?

Thank you very much to whoever replies.

  1. You can’t have ? in file names. They get converted to _
  2. You have the quotation marks in your script and so you get them in the file name.
  3. samplerate should be sample_rate, bitdepth should be bitrate.
2 Likes

First off, I strongly discourage trying to use AI for writing Picard scripts. From what I’ve seen, it rarely ends up well. I also recommend reviewing the section on scripting and the tutorial for writing a file naming script in the Picard User Guide.

That’s normal, because that’s the only time the file naming script is executed. It wouldn’t make much sense to run it if you weren’t moving or renaming the files.

The reason it is showing '_'-'_' is because it’s not finding a value for %_samplerate% or %_bitdepth% so is using the '?' fallback (including the single quotes which are not required when specifying a string). It is then replacing the question mark with an underscore because the question mark is not a valid path character. You have a couple of options:

  1. Replace all occurrences of '?' in your script with something like Unknown.
  2. Remove all occurrences of '?' in your scripts and not replace them with anything.
  3. Replace all occurrences of '?' in your script with a default value more appropriate to that specific variable, such as:
$set(_year,$left($if2(%originaldate%,%date%,0000),4))
$set(_format,$upper(%_extension%))
$set(_audio,$if2(%_sample_rate%,0)-$if2(%_bitrate%,0))
$set(_catno,$if2(%catalognumber%,No Cat Number))
$set(_label,$if2(%label%,No Label))
$if2(%albumartist%,%artist%)
- %album% \(%_year%\) %_format% %_audio% %_catno%
%_label%/$num(%tracknumber%,2) - %title%

For what it’s worth, I recommend the third option and using the script I provided.

3 Likes

Really thank so much for your help! I apreciate…

I tried your script but MP give me this error:

3:32: Unexpected character ‘,’

I think ithere is a comma at row 3 caharcter 32?

There is a % missing after sample_rate.

1 Like

As @Sophist said, there should actually be a percent sign before the comma. I’ve updated my post to include this so that the script should now run.

1 Like

Definitive version of script:

`$set(_year,$left($if2(%originaldate%,%date%,0000),4))`

`$set(_format,$upper(%_extension%))`

`$set(_audio,$if2(%_bits_per_sample%,0)-$div($if2(%_sample_rate%,0),1000))`

`$set(_catno,$if2(%catalognumber%,No Cat Number))`

`$set(_catno,$replace(%_catno%, ,_))`

`$set(_catno,$replace(%_catno%,-,_))`

`$set(_label,$if2(%label%,No Label))`

`$if2(%albumartist%,%artist%) - %album% \(%_year%\) %_format% %_audio% %_catno% %_label%/$num(%tracknumber%,2) %title%`

Another question for you: from a directroy like this:

Cirque Du Soleil - Iris

the result is:

Cirque Du Soleil - Iris (2011) FLAC 16-44 CDSMCD_10042_2 Cirque du Soleil Musique

I was wondering how about a directory structure like this:

artist - title/CD 01 or /CD 02

It’s seems logical rename only root directory….

I’m trying to improve my script and I added some variables:

`$set(_albumartistname,$swapprefix(%albumartist%))`
`$set(_artistname,$swapprefix(%albumartist%))`
`$set(_cdno,$if($gt(%totaldiscs%,1),%discnumber%CD))`

and the directories name will become:

$if2(%_albumartistname%,%_artistname%) - %album% %_cdno% (%_year%) %_format% %_audio% %_catno% %_label%/$num(%tracknumber%,2) %title%

So, the “artist name” will be write like this:

Beatles, The

instead of:

The Beatles

and if the album has more than 1 disc (ex. 2CDs) in the directories title I will have:

Beatles, The - 1962 – 1966 (2023 Edition) 2CD

Have you any suggestion?

I’m reading guidelines and I have updated again my script with support for NDiscs and different directories for each disc under the “mother” directory

$set(_year,$left($if2(%originaldate%,%date%,0000),4))
$set(_format,$upper(%_extension%))
$set(_audio,$if2(%_bits_per_sample%,0)-$div($if2(%_sample_rate%,0),1000))
$set(_catno,$if2(%catalognumber%,No Cat Number))
$set(_catno,$replace(%_catno%, ,_))
$set(_catno,$replace(%_catno%,-,_))
$set(_label,$if2(%label%,No Label))
$set(_albumartistname,$swapprefix(%albumartist%))`
$set(_artistname,$swapprefix(%albumartist%))`

# Set basic path for mother dir
$set(_basepath,$if2(%_albumartistname%,%_artistname%) - %album% \(%_year%\) %_format% %_audio% %_catno% %_label%)

# If a multi disc album add a sub directory "Disc X" to path 
$if($gt(%totaldiscs%,1),$set(_basepath,%_basepath%/Disc %discnumber%))

# Join mother dir to filename
%_basepath%/$num(%tracknumber%,2) %title%

script seems work properly…
but there is something which doesnt work anymore:

I set in “Renaming file” all options:

move files, rename file, directory where to put files, and also move other files as “.” ;
but it doesnt move alla things I have in original directory…

It expects file name patterns to match, where “*” matches anything and “?” matches a single character. Try setting it to a single “*” to match all files.

2 Likes

It expects file name patterns to match, where “” matches anything and “?” matches a single character. Try setting it to a single “” to match all files.

Thank so much for your answer;
@outsidecontext
Could you explain better please?

The “Move additional files” setting expects one or multiple filename patterns to move. It moves files that match these patterns. You can for example directly enter a specific filename to move:

booklet.pdf

This will move exactly the file “booklet.pdf” if it is in the same directory as the audio file being saved. But you can also specify file name patterns where a * symbol matches any amount of characters, and a ? matches exactly one character.

So if you would like to move all files ending with “.pdf” you could set the patter:

*.pdf

Or for any filename just use a single:

*
2 Likes

I see
actually I put " * . * " … I’ll try with * only

1 Like

*.* would also work if all your files have a file extension / contain a dot. What are the files it doesn’t move?

It partially works!

" * " works (* . * do not) but it moves only files which originally are in directory 1CD;
it doesnt move directories or other files which are in “mother” directory wich contains CD 01 CD 02 …and artwork

maybe something wrong in path directories?

Before I gave a old script version:

this is last one:

$set(_year,$left($if2(%originaldate%,%date%,0000),4))
$set(_format,$upper(%_extension%))
$set(_audio,$if2(%_bits_per_sample%,0)-$div($if2(%_sample_rate%,0),1000))
$set(_catno,$if2(%catalognumber%,No Cat Number))
$set(_catno,$replace(%_catno%, ,_))
$set(_catno,$replace(%_catno%,-,_))
$set(_label,$if2(%label%,No Label))

$set(_albumartistname,$swapprefix(%albumartist%))
$set(_artistname,$swapprefix(%albumartist%))

$set(_basepath,$if2(%_albumartistname%,%_artistname%) - %album% \(%_year%\) %_format% %_audio% %_catno% %_label%)

$if($gt(%totaldiscs%,1),$set(_basepath,%_basepath%/Disc %discnumber%))

%_basepath%/$num(%tracknumber%,2) %title%

It can only move files or folders that are inside of the directory the original file is inside.

1 Like

Thank for your answer!
And sorry… maybe I do not explain correctly

If I have a album with more than 1 CD and I have a structure like this:

Artist - Title

  • cd 1
  • cd 2
  • artwork

correctly it creates the directory with name I set in script;
correctly it creates Disc 1 and Disc 2 directories with their file;
but it doesnt move “artwork” in new mother directory!!!

CD1 and CD2 hold audio files that Picard is manipulating. So it can understand to move everything else in those folders to the new location.

Artwork is a folder with nothing in it that Picard is aware of. So Picard has no concept of that folder existing so cannot move it.

Picard is only working within the current folder with the actual audio files. Not on the level above that. Or in your terms, it only knows of the children with audio files in it. It has no concept of what else the mother folder holds.

2 Likes