<?
/*----------------- Put your path here --------------*/
$path_a="/app8/www2";
$path_b="/app8/www";
/*---------------------------------------------------*/
function listDir($path){
global $fileinfo,$dirinfo;
//which file or directory you don't want update,please type here
$seekFile=array(".","..","lost+found",".kde");
if(!file_exists($path)){
die("'".$path."'directory is not exists \n");
}
$handle=dir($path);
while ($entry = $handle->read()) {
if(in_array($entry,$seekFile)){
continue 1;
}
$f=$path."/".$entry;
if(is_dir($f)){
$dirinfo[$f]=1;
listDir($f);
}else{
$filetime=filemtime($f);
$fileinfo[]=array(
'path'=>$path,
'name'=>$f,
'time'=>$filetime
);
//echo $filetime." - ".$f."<br>";
}
}
}
function copyFile($path_from,$path_to){
global $fileinfo,$dirinfo;
//Check Directory
if(!file_exists($path_from)){
die("'".$path_from."'directory is not exists \n");
}
//Check directory
if(!file_exists($path_to)){
die("'".$path_to."'directory is not exists \n");
}
//Create all directory if not exists
while(list($key,$val)=each($dirinfo)){
$new_path=ereg_replace("^".$path_from,$path_to,$key);
if(!file_exists($new_path)){
echo "Create directory: ".$new_path."\n";
mkdir($new_path,0777);
}
}
//Start Copy File
while(list($key,$val)=each($fileinfo)){
$src_name=$val['name'];
$src_time=$val['time'];
$new_name=ereg_replace("^".$path_from,$path_to,$src_name);
if(file_exists($new_name)){
if($src_time>filemtime($new_name)){
unlink($new_name);
copy($src_name,$new_name);
echo "updated file: $new_name \n";
}
}else{
echo "copy file to $new_name \n";
copy($src_name,$new_name);
}
}
}
echo "<pre>\n";
$fileinfo=array();
$dirinfo=array();
listDir($path_a);
copyFile($path_a,$path_b);
echo "\n</pre>";
?> |