ImageGrid/scripts/flatten.sh
2016-01-07 03:42:02 +03:00

31 lines
502 B
Bash
Executable File

#!/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