PHP - Compare directories for file changes

On the heels of my last php script, I had to modify this slightly to compare our version of a website (in this case a joomla website) against a vanilla version of the joomla install.

It was fairly straight forward…

 

On a local webserver I created a folder called compare. In there I created two directories… one calle ‘branch’ and another called ‘ vanilla’. Also in this directory is where I placed the phpscript below.

In the vanilla folder i placed the original joomla code and in the branch folder I placed a copy of the modified website. Then I ran the script:

  function compareDirectories( $path = ‘.’, $level = 0 ){
$ignore = array( ‘cgi-bin’, ‘.’, ‘..’ );
$dh = ( $path );
while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory

nbsp; if( !in_array( $file, $ignore ) ){

if( is_dir( “$path/$file” ) ){
nbsp; // Its a directory, so we need to keep reading down…
nbsp; compareDirectories( “$path/$file”, ($level+1),$time );

} else {
nbsp; compareFiles(”$path/$file”);
}//elseif

nbsp; }//if in array

}//while
closedir( $dh );
}
 
function compareFiles( $path = ‘.’ ){
$vanilla_path = $path;
$branch_path = str_replace(”vanilla”,”branch”,$path);
if(file_exists($branch_path)){
if( strcmp(file_get_contents($vanilla_path),file_get_contents($branch_path)) ){
echo “$vanilla_path $branch_path -DIFFERENCE DETECTED
”;

nbsp; }

}
return true;
}
compareFiles( “./vanilla”,0);

?>



Basically it produces a list of files that differ from the vanilla version…

Comments
Add New
Powered by !JoomlaComment 3.26

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Help my beer fund

RocketTheme Joomla Templates