hack4mer / diffon
一个PHP库,用于查找两个给定目录之间的差异
v1.1.2
2018-10-21 09:41 UTC
This package is auto-updated.
Last update: 2024-09-21 22:55:29 UTC
README
一个PHP库,用于查找两个给定目录之间的差异
关于目录提供以下信息
- 仅存在于第一个目录中的文件/目录。
- 仅存在于第二个目录中的文件/目录。
- 存在于两个目录中的文件/目录。
- 存在于两个目录中的文件,但包含不同的数据。
但是,如果目录存在于两个目录中且包含不同的内容呢?为了这个,我们应该在我们的代码中实现具有递归的Diffon。
安装
composer require hack4mer/diffon
用法
假设您有两个目录,其内容如下
dir1 => hack4mer.txt, github.txt, winter.txt
dir2 => hack4mer.txt (with different content), github.txt, summer.txt
使用Diffon比较目录
<?php
//include composer autoloader
include 'vendor/autoload.php'
use Hack4mer\Diffon\Dinffon;
$diffon = new Diffon();
$diffon->setSource("dir1")->setDestination("dir2");
$difference = $diffon->diff();
print_r($difference);
?>
输出
Array
(
[only_in_source] => Array
(
[2] => winter.txt
)
[only_in_destination] => Array
(
[2] => summer.txt
)
[in_both] => Array
(
[0] => github.txt
[1] => hack4mer.txt
)
[not_same] => Array
(
[1] => hack4mer.txt
)
)
注意数组元素的索引,它们提供了如果按字母顺序排序,每个文件在给定目录中的位置信息。