Some time ago I made this script, to make calibre put books in correct directories on my device. You need to create "Custom column based on other columns" and put the output of the script in "Template" field. Then connect the device, go to "Device" -> "Configure this device" -> "Save template", and put something like "{#column_name}". You need to adjust the tags in the script yourself (starts at lie 16 ends at 60).
https://gist.github.com/Galunid/fe82...3b0b0309b7adb0