<?php
$dirs = array('/www/oa/lib','/www/oa/module','/www/oa/www/main/js','/www/oa/www/main/css');//要同步的目录
$count = 0;
foreach($dirs as $dir){
checkDir($dir);
}
echo "\033[7;35m".' Complete> Total checked files: '.$count."!\033[0m".chr(10);
function checkDir($_dir){
if(strlen(str_replace('/','',$_dir))<3) return;//防止删除/,增强安全性
$dirs = scandir($_dir);
if(count($dirs)<3) return;// echo $_dir.' is empty!'.chr(10);
//else echo $_dir.' = '.count($dirs).chr(10);
foreach($dirs as $dir){
if($dir=='.'||$dir=='..') continue;
$dir= $_dir.'/'.$dir;
if(is_dir($dir))
checkDir($dir);
else
checkFile($dir);
}
}
function checkFile($file){
global $count;
$count++;
$ext = substr($file,-3);
if($ext!='php'&&$ext!='.js'&&$ext!='css') return;
$file1 = str_replace('/www/oa/', '/www/oa_p/', $file);//目的目录,将源目录与目的目录的不同之处替换为目的目录的
$cmd = false;
$size = filesize($file);
$size1 = 0;
if(!is_file($file1)){
$cmd = 'cp -f '.$file.' '.$file1;
}else{
$size1 = filesize($file1);
if($size!=$size1){
//echo $size.'-'.$size1.chr(10);
$cmd = 'cp -f '.$file.' '.$file1;
}
}
if($cmd){
echo ' * Update '.$file.'(Size from '.$size1.' to '.$size.'), Done.'.chr(10);
exec($cmd);
}
}