#文件所在的路径
xdrBasePath='/data/test'
echo 'xdr文件根路径:'${xdrBasePath}
for file in ${xdrBasePath}/*.txt.gz;
do
##截取文件里面的日期信息
#1,获取文件名.包含后缀
filename=$(basename $file)
echo '文件名:'${filename}
#2,截取时间:TSMTPP2735D20170517142005E981.txt.gz
timeyear=${filename:11:4}
timemonth=${filename:15:2}
timeday=${filename:17:2}
#echo '解析出的到年的时间:'${timeyear}
#echo '解析出的到月的时间:'${timemonth}
#echo '解析出的到日的时间:'${timeday}
yeardirpath=${xdrBasePath}/${timeyear}
monthdirpath=${yeardirpath}/${timemonth}
daydirpath=${monthdirpath}/${timeday}
#echo $yeardirpath
#echo $monthdirpath
#echo $daydirpath
#判断文件夹是否存在,不存在就创建
if [ ! -e ${yeardirpath} -o ! -d ${yeardirpath} ]; then
mkdir ${yeardirpath}
fi
if [ ! -e ${monthdirpath} -o ! -d ${monthdirpath} ]; then
mkdir ${monthdirpath}
fi
if [ ! -e ${daydirpath} -o ! -d ${daydirpath} ]; then
mkdir ${daydirpath}
fi
#将文件移动到改目录下
mv -f ${xdrBasePath}/${filename} ${daydirpath}
#echo '-------------------------'
done