shell遍历文件夹

#### 参数1:文件名
function CopyFile()
{
 LogStr="Copy file from BASE_DATA_DIR/${1} to ${NA_OUTPUT_DIR}${NA_FILEHEAD}${1}"
 PutLog "$LogStr"
 cp $BASE_DATA_DIR/${1} ${NA_OUTPUT_DIR}${NA_FILEHEAD}${1}
}


#### 遍历文件夹
#### 参数1:要遍历的路径
#### 参数2:对遍历结果的回调函数,此函数的参数为文件名。
function TransFiles()
{
 Dir=${1}

 PutLog "Dir = $Dir"

 FileList=`ls $BASE_DATA_DIR | grep .unl`

 PutLog "FileList=$FileList"

 FileNum=1

 while [ 1 ] ;
 do
  FileName=`echo $FileList | cut -d' ' -f $FileNum`

  if [ X$FileName ==  X ];
  then
   break;
  fi

  ${2} $FileName

  ((FileNum++));
 done
}

TransFiles "$BASE_DATA_DIR" CopyFile

原文地址:https://www.cnblogs.com/aoyihuashao/p/2674691.html