diff --git a/scripts/flatten.sh b/scripts/flatten.sh new file mode 100755 index 00000000..133433ff --- /dev/null +++ b/scripts/flatten.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +shopt -s extglob + +SCRIPT_DIR="`dirname $0`" + +# we operate only on the dir the script is in... +cd $SCRIPT_DIR + +if ! [ -e "ALL" ] ; then + mkdir "ALL" +fi + +find . -path ./ALL -prune -o -iregex ".*\(jpg\|png\|gif\)" -printf ./%P\\0 | while read -d '' f ; do + echo "$f" + to=${f//.\//} + mv "$f" "./ALL/${to//\// - }" + + # cleanup... + while [[ $f != "." ]] ; do + f=`dirname ./"$f"` + f=${f//.\//} + + if ! [ "`ls -A ./\"$f\"`" ] ; then + echo "removing empty: $f" + rmdir ./"$f" + fi + done +done +