#!/bin/bash
#desc: get file from directory
#example: sh getfilefromdir.sh A B
INIT_PATH=${1%/}
SAVE_PATH=${2%/}
function checksavepath() {
if [ -d $SAVE_PATH ]
then
rm -rf $SAVE_PATH
fi
mkdir ${SAVE_PATH}
touch $SAVE_PATH".log"
}
function getfilefromdir(){
for file in ` ls $1`
do
if [ -d $1"/"$file ]
then
getfilefromdir $1"/"$file
else
local path="$1/$file"
local name=$file
if [ ! -f $SAVE_PATH"/"$name ]
then
echo "cp ${path} to ${SAVE_PATH}/${name}"
cp ${path} "${SAVE_PATH}/${name}"
else
echo "${path} file already exists"
echo "${path}" >> $SAVE_PATH".log" 2>1
fi
fi
done
}
checksavepath
for sfol in ${INIT_PATH}
do
getfilefromdir ${sfol}
done