#!/bin/sh
rootPath=`pwd`
dst=$rootPath/lua
src=$rootPath/clientlua
echo "dst $dst src $src"
declare -A map

function handleSrc()
{
    echo "handle src $1 start"
	docfiles=$(ls $1/)
    for sfile in ${docfiles}
    do
		echo "foreach file $sfile"
			#是文件夹
        if [ -d $1/$sfile ];then
			#向下清除meta文件和改文件名
			handleSrc $1/$sfile $2
		elif [ "${sfile##*.}"x = "txt"x ];then
			#重命名txt文件
			echo "重命名txt文件 ${sfile} to ${sfile%.txt}"
			#mv $1/$sfile $1/${sfile%.txt}
			key=${sfile%.txt}
			result=${map[$key]}
			if [ "$result" = "1" ];then
				s=$1/$sfile
				d=$2/${key}
				echo "s=$s d=$d"
				cp -r $s $d
			fi
        fi
    done
    echo "handle src $1 end"
}

function handleDst()
{
	echo "handle dst $1 start"
	docfiles=$(ls $1/)
	for sfile in ${docfiles}
    do
		map[$sfile]="1"
    done
    echo "handle dst $1 end ${!map[@]}"


}

handleDst $dst
handleSrc $src $dst
sleep 5
rm -rf $src/*

