<?php
if
(
count
(
$argv
) > 1 )
$dir1
= del_postfix(
$argv
[1]);
else
$dir1
= '/';
if
(
count
(
$argv
) > 2 )
$dir2
= del_postfix(
$argv
[2]);
else
$dir2
= '/';
process_compare(
$dir1
,
$dir2
, 0);
echo
"===========================================================\n"
;
process_compare(
$dir2
,
$dir1
, 1);
echo
"all OK\n"
;
function
del_postfix(
$dir
)
{
if
(!preg_match('#^/#',
$dir
)) {
throw
new
Exception('参数必须是绝对路径');
}
$dir
= preg_replace('#/$#', '',
$dir
);
return
$dir
;
}
function
process_compare(
$dir1
,
$dir2
,
$only_check_has
){
compare_file_folder(
$dir1
,
$dir1
,
$dir2
,
$only_check_has
);
}
function
compare_file_folder(
$dir1
,
$base_dir1
,
$base_dir2
,
$only_check_has
=0){
if
(
is_dir
(
$dir1
)) {
$handle
= dir(
$dir1
);
if
(
$dh
= opendir(
$dir1
)) {
while
(
$entry
=
$handle
->read()) {
if
((
$entry
!=
"."
) && (
$entry
!=
".."
) && (
$entry
!=
".svn"
)){
$new
=
$dir1
.
"/"
.
$entry
;
$other
= preg_replace('#^'.
$base_dir1
.'#' ,
$base_dir2
,
$new
);
if
(
is_dir
(
$new
)) {
if
(!
is_dir
(
$other
)) {
echo
'!!not found direction: '.
$other
. ' (' .
$new
.
")\n"
;
}
compare_file_folder(
$new
,
$base_dir1
,
$base_dir2
,
$only_check_has
) ;
}
else
{
if
(!
is_file
(
$other
)) {
echo
'!!not found file: '.
$other
. ' ('.
$new
.
")\n"
;
}
elseif
(
$only_check_has
==0 && ( md5_file(
$other
) != md5_file(
$new
) ) ){
echo
'!!file md5 error: '.
$other
. ' ('.
$new
.
")\n"
;
}
}
}
}
closedir
(
$dh
);
}
}
}
?>