Skip to content

Instantly share code, notes, and snippets.

@y-matsumoto
Created October 7, 2015 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-matsumoto/4b23050754014e9eb868 to your computer and use it in GitHub Desktop.
Save y-matsumoto/4b23050754014e9eb868 to your computer and use it in GitHub Desktop.
Androidプロジェクト(Eclipse版) - 使用していないイメージ画像を削除
#!/bin/sh
if [ $# -ne 1 ]; then
echo "argument error"
exit 1
fi
echo "start"
PROJECT_NAME=$1
IMG_DIRECTORY=${PROJECT_NAME}"/res/drawable-*"
SEARCH_DIRECTORY1=${PROJECT_NAME}"/src"
SEARCH_DIRECTORY2=${PROJECT_NAME}"/res/layout"
SEARCH_DIRECTORY3=${PROJECT_NAME}"/res/menu"
SEARCH_DIRECTORY4=${PROJECT_NAME}"/res/drawable"
SEARCH_FILE1=${PROJECT_NAME}"/AndroidManifest.xml"
use_img_lst=()
unused_img_lst=()
for line in `find ${IMG_DIRECTORY} -type f | sort | uniq`; do
file=`echo ${line} | sed -e 's!^.*/!!' -e 's!.9.png$!!' -e 's!.png$!!' -e 's!.jpg$!!'`
if grep -r ${file} ${SEARCH_DIRECTORY1} ${SEARCH_DIRECTORY2} ${SEARCN_DIRECTORY3} ${SEARCH_DIRECTORY4} ${SEARCH_FILE1} > /dev/null 2>&1; then
echo "use:" $line
use_img_lst=("${use_img_lst[@]}" $line)
else
echo "nonuse:" $line
unused_img_lst=("${unused_img_lst[@]}" $line)
fi
done
echo "export complete [use imagefile list]"
for elem in ${use_img_lst[@]}; do
echo $elem >> use-output.txt
done
echo "export complete [unused imagefile list]"
for elem in ${unused_img_lst[@]}; do
echo $elem >> unused-output.txt
rm -r $elem
done
echo "complete"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment