#!/bin/bash ## Resample FLAC files # Output directory output="/home//processed-files" if [ -d $output ] then echo "Folder already exists" else mkdir $output fi # start loop find . -name '*.flac' | while IFS=$'\n' read -r FILE do # Get file name and path outputfile="$(basename "$FILE")" DIR=$(dirname "$FILE") # Remove the leading dot and append to ouput path DIR=$output${DIR#.} # Create new folder if it does not exist if [[ ! -d $DIR ]] then mkdir -p "$DIR" echo "created"$DIR fi # Do the conversion sox -S "$FILE" -r 48000 "$DIR/$outputfile"\ || echo "error processing: $FILE" done