#!/bin/bash getDestDir() { if [ -n "${destinationrenamepath[$destination]}" ] \ && ( ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{album\}?([^\]])* ]] \ && [ -n "$album" ] ) || ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{albumartist\}?([^\]])* ]] \ && [ -n "$albumartist" ] ) || ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{artist\}?([^\]])* ]] \ && [ -n "$artist" ] ) || ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{genre\}?([^\]])* ]] \ && [ -n "$genre" ] ) || ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{title\}?([^\]])* ]] \ && [ -n "$title" ] ) || ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{track\}?([^\]])* ]] \ && [ -n "$track" ] ) || ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{year\}?([^\]])* ]] \ && [ -n "$year" ] ) || ( [[ ${destinationrenamepath[$destination]} == \ *?([^[])%\{disc\}?([^\]])* ]] \ && [ -n "$disc" ] ) ) then destdir="${destinationpath[$destination]}/" if (( ${destinationascii["$destination"]} )) then echo "$album" >&${toascii[1]} read -r -u${toascii[0]} album echo "$albumartist" >&${toascii[1]} read -r -u${toascii[0]} albumartist echo "$artist" >&${toascii[1]} read -r -u${toascii[0]} artist echo "$genre" >&${toascii[1]} read -r -u${toascii[0]} genre echo "$title" >&${toascii[1]} read -r -u${toascii[0]} title echo "$tracknumber" >&${toascii[1]} read -r -u${toascii[0]} tracknumber echo "$year" >&${toascii[1]} read -r -u${toascii[0]} year echo "$disc" >&${toascii[1]} read -r -u${toascii[0]} disc fi replace=$(sanitizeFile "$album" dir) destdir+="${destinationrenamepath[$destination]//?(\[)%\{album\}?(\])/$replace}" replace=$(sanitizeFile "$albumartist" dir) destdir="${destdir//?(\[)%\{albumartist\}?(\])/$replace}" replace=$(sanitizeFile "$artist" dir) destdir="${destdir//?(\[)%\{artist\}?(\])/$replace}" replace=$(sanitizeFile "$genre" dir) destdir="${destdir//?(\[)%\{genre\}?(\])/$replace}" replace=$(sanitizeFile "$title" dir) destdir="${destdir//?(\[)%\{title\}?(\])/$replace}" tracknumber="${track%/*}" replace=$(sanitizeFile "$tracknumber" dir) destdir="${destdir//?(\[)%\{track\}?(\])/$replace}" replace=$(sanitizeFile "$year" dir) destdir="${destdir//?(\[)%\{year\}?(\])/$replace}" replace=$(sanitizeFile "$disc" dir) destdir="${destdir//?(\[)%\{disc\}?(\])/$replace}" else destdir="${destinationpath[$destination]}/" destdir+=$(sanitizeFile "${filename%%/*}" dir) part=${filename#*/} while [[ $part =~ / ]] do thispart="${part%%/*}" if (( ${destinationascii["$destination"]} )) then echo "$thispart" >&${toascii[1]} read -r -u${toascii[0]} thispart fi destdir+="/$(sanitizeFile "$thispart" dir)" part=${part#*/} done fi if ! [ -d "$destdir" ] then mkdir -p "$destdir" fi destdir="${destdir//+(\/)//}" }