`
Eileenlml
  • 浏览: 70135 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

遍历文件夹里的文件格式

 
阅读更多

#!/bin/sh

. $HOME/.profile

 

DIRECTORY=/data/tran_data/20170526

LOGDIR=/data/tran_data/20170526/log

LOG=$LOGDIR/countdir.log

begin1=`date +"%m/%d/%Y %T"`

 

txt_count=0  

xml_count=0  

map_count=0  

other_count=0 

 

mail_user=""

 

DIRECTORY=$1  

if [ "`ls -A $DIRECTORY`" = "" ]; then  

  echo "$DIRECTORY is empty"  

else  

  echo "$DIRECTORY is not empty"  

fi  

  

    for file in ` ls $DIRECTORY `  

    do  

        if [ -f $DIRECTORY"/"$file ]  

        then  

        fileType=${file##*.}  

                        if [ "$fileType" = "txt" ];  

                         then  

                          txt_count=$(($txt_count+1))  

                        elif  [ "$fileType" = "xml" ];  

                         then  

                          xml_count=$(($xml_count+1))  

                        elif  [ "$fileType" = "map" ];  

                         then  

                          map_count=$(($map_count+1))  

                        else  

                          other_count=$(($other_count+1))  

                        fi  

                fi  

    done  

echo "'txt file count:'$txt_count" >>$LOG  

echo "'xml file count:'$xml_count" >>$LOG 

echo "'map file count:'$map_count" >>$LOG 

echo "'other file count:'$other_count" >>$LOG 

 

end1=`date +"%T"`

echo "Begin=[ ${begin1} ] - End=[ ${end1} ]">>$LOG 

mailx -s "COUNTDIR, Begin=[ ${begin1} ] - End=[ ${end1} ]" ${mail_users} < /data/tran_data/20170526/$LOG 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics