4in1_tools/validate_tiff.sh
2024-07-25 02:58:08 +03:00

44 lines
752 B
Bash
Executable File

#!/bin/sh
# NOTE: tifftopnm is a part of netpbm package
usage() {
echo "Usage: $0 [--delete]"
echo
echo "This script checks if TIFF files in the current directory are valid and prints invalid ones."
echo
echo "Options:"
echo " --delete Delete invalid TIFF files."
echo " --help Display this help message."
}
DELETE_FILES=false
for arg in "$@"; do
case $arg in
--delete)
DELETE_FILES=true
;;
--help)
usage
exit 0
;;
*)
echo "Unknown argument: $arg" >&2
usage >&2
exit 1
;;
esac
done
for f in *.tif; do
echo -n "$f... "
tifftopnm "$f" 2>&1 >/dev/null | grep -i error >/dev/null && {
if [ "$DELETE_FILES" = true ]; then
rm "$f"
echo -n "DELETED"
else
echo -n "ERROR"
fi
}
echo
done