FOR循环遍历两个文件夹

荒野

我有两个文件夹要比较,但是使用diff -r做到这一点并不是那么简单。

我使用的是一个小的条件函数,而不是diff。也许函数本身很重要,所以我将其粘贴在这里。

function timeDiff() {

local time1="$(head -n 1 "$1")"

local time2="$(head -n 1 "$2")"

    echo $time1
  echo $time2

  if (( "$time1" < 60)) && (( "$time2" < 60)); then  

  echo No comparision needed. 

  else

    diff $1 $2

    fi
}

现在。我有2个文件夹,它们当前如下所示:

Folder name: 1    Folder name: 2
1.txt             1.txt
2.txt             2.txt

这是我眼中的盐。第二个功能。目的是(可能包含伪代码):

  1. 在for循环中,遍历两个文件夹,获取第一个文件1.txt,检查1.txt第二个文件夹中是否有相同名称的文件,如果存在,请timeDiff对它们运行该功能,然后转到下一个文件(1/2.txt``2/2.txt),依此类推。并不断。

现在,第二个函数看起来像这样:

function recuDiff() {
    for file1 in $1 && file2 in $2
    do
     timeDiff $file1 $file2
    done

}

我尝试了几次,但似乎没有找到一种方法来至少在多个条件下运行for循环...

史蒂文·潘尼
function recuDiff {
  find 1 -maxdepth 1 -mindepth 1 -printf '%P\n' |
  while read each
  do
    if [ -e 2/"$each" ]
    then
      timeDiff {1,2}/"$each"
    fi
  done
}
  1. 在里面找到东西 1
  2. 如果存在2,运行timeDiff

但是,我必须说最好/更轻松的方法是对中不存在的文件进行检查timeDiff

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章