...

View Full Version : Compare two files for changes



amir
11-10-2006, 04:02 PM
My goal is to compare two files with the same name and determine what the differences are between the newer and the older file so I can update the older file to match the newer one. I hope that makes sense.

Currently Im just trying to figure out a good way to parse two files and determine what the changes are without loading the entire files into memory via the file() function; I would prefer to use a while loop with fread and feof if possible to reduce the amount of memory needed during the calculations.

Anyone have any ideas?

Thanks!

crunkbbfe
11-10-2006, 04:22 PM
My goal is to compare two files with the same name and determine what the differences are between the newer and the older file so I can update the older file to match the newer one. I hope that makes sense.

Currently Im just trying to figure out a good way to parse two files and determine what the changes are without loading the entire files into memory via the file() function; I would prefer to use a while loop with fread and feof if possible to reduce the amount of memory needed during the calculations.

Anyone have any ideas?

Thanks!



maybe use filesize and get the size of each file and if the file size of the newer one is different from the older one then take the contents of the file using fread and rewrite it to the older file




<?
$new1 = filesize("newsite.html");
$old1 = filesize("oldsite.php");
if($new1 != $old1){
$newsite = "newsite.html";
$oldsite = "oldsite.php";
$qr = fopen($oldsite, 'w') or die("Could not open file");
$qw = fopen($newsite, 'r') or die("Could not open file");
$read = fread($qw, filesize($newsite));
fwrite($qr, $read);
echo "File has been successfully updated!";
}else{
echo "Site already the same";
}

?>

vinyl-junkie
11-10-2006, 05:12 PM
Is ExamDiff (http://www.prestosoft.com/ps.asp?page=edp_examdiff) something you could use to compare your two files?

amir
11-10-2006, 05:22 PM
Thanks Guys!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum