#!/bin/bash

ERROR_LOG=error.log
#find . -name $ERROR_LOG | xargs rm -f
rm -f $ERROR_LOG
FILE_NAME_SUFFIX_LOG=file_name_suffix.log
rm -f $ERROR_LOG $FILE_NAME_SUFFIX_LOG
#bmp :  BMP3
#BMP :  BMP3
#gif :  GIF
#GIF :  GIF
#gif :  JPEG
#jpeg :  JPEG
#jpe :  JPEG
#jpg :  JPEG
#JPG :  JPEG
#png :  JPEG
#PNG :  PNG
#tif :  TIFF
#TIF :  TIFF
PIC_DIR=pic
IMG_LIST_FOR_WEB=image_list_for_both.txt
ALL_FILE_NUM=0

NUM=0
for i in `ls` ; do
    if [ -d $i  ] ; then 
	    let NUM+=1

	    FILE_NUM=`wc -l $i/$IMG_LIST_FOR_WEB | awk '{print $1}'`
	    let ALL_FILE_NUM+=$FILE_NUM

	    if  [ -d $i/$PIC_DIR ] ;then
                rm -rf $i/$PIC_DIR
            fi
	    if ! [ -e $i/$PIC_DIR ] ;then
		    mkdir $i/$PIC_DIR
	    elif ! [ -d $i/$PIC_DIR ] ;then
		    echo "not a dir,but a file name,exit"
		    echo "not a dir,but a file name,exit"   >>  $ERROR_LOG
		    exit
	    fi

	    echo "$NUM: $i"
	    #./check_file_name.sh $i
	    ./convert_image_file.sh $i

    fi
done

echo "Finished:total $NUM sub-dirs"
echo "all image entries in these sub-dirs' record :$ALL_FILE_NUM"
echo "To see if errors occured, check if there are $ERROR_LOG (maybe under sub dirs)"
