Quote:
Originally Posted by jamesan
TOP=/media_library
FLAC=$TOP/flacfiles
WAV=$TOP/wavfiles
find $FLAC/* | while read f
do
cmd="echo $f | sed 's?^$FLAC?$WAV?'"
g="$(eval $cmd)"
d=${g%/*}
# echo "mkdir -p $d"
mkdir -p $d
if [ -d $f ]; then
continue
fi
ext=${f##*.}
if [ "$ext" == "flac" ]; then
BASEFLAC=`basename $f`
FLACDIR=`dirname $f`
WAVDIR=`dirname $g`
# echo "cd $FLACDIR"
cd $FLACDIR
# echo "flac -d $BASEFLAC --output-prefix=$WAVDIR/ || exit 1"
flac -d $BASEFLAC --output-prefix=$WAVDIR/
fi
done[/CODE]
|
that's the reason why you must test (thru echo) before
actually doing the conversion
I'll try to explain
The idea is to store the output files in a tree similar to
the input files (except for the top directory which
for the input files is $FLAC and it exists
for the output files is $WAV and it doesn't necessarily exists
1. first we look for all files/folders/subfolders in the input
directory $FLAC
find $FLAC/* | while read f
do
...
done
2.
cmd="echo $f | sed 's?^$FLAC?$WAV?'"
g="$(eval $cmd)"
the 2 lines above help us form the target path
we can't directly do g=$(echo $f | sed 's?^$FLAC?$WAV?'")
that wouldn't work (eval replaces the variables FLAC and WAV
by their actual values before executing sed)
d=${g%/*}
this one forms the directory part of the complete path $g
so for instance, if the input file is
/media_library/flacfiles/folder0/folderA/file.avi
g is gonna be
/media_library/wavefiles/folder0/folderA/file.avi
and d: /media_library/wavefiles/folder0/folderA
mkdir -p $d
we create the directory $d if it doesn't already exist
if [ -d $f ]; then
continue
fi
if $f is a directory proceed, do nothing
ext=${f##*.}
this store the extension of the file in the variable ext
if the test below is true
if [ "$ext" == "flac" ]; then
do the conversion
...
These shell constructions are quite useful (and more efficient
than the commands 'basename', 'sed', etc.) so whenever you can use
them do so
g=${f##*/} : filename (without the directory part)
n=${g%.*} : name (without the extension)
hope this is clear enough