Legend:
Options:
Right Side: $File2
"; //Other Options $FileSeparator="\n"; //Should be "\r\n" for Windows text files $DirectorySeparator="/"; //Should be "\\" for Windows $StringSeparator="\t"; //The file's data string separator //Extract the directory/file contents structures from both lists $Contents=Array(file_get_contents($File1), file_get_contents($File2)); $Structures=Array(); for($i=0;$i<2;$i++) { $MyStructure=Array(); //Create the contents structure root $MyFiles=explode($FileSeparator, $Contents[$i]); //Extract the list of files and their confirmation string foreach($MyFiles as $File) //Add each file to the contents structure { $FileInfo=explode("\t", $File); //Separate the path and the file confirmation string if(count($FileInfo)!=2) //Bypass invalid lines continue; $FilePath=explode($DirectorySeparator, $FileInfo[0]); //Extract the parent directories and the filename $NumDirectories=count($FilePath)-1; //The number of directories is 1 minus the number of entries because the last entry is the file name $CurrentDirectory=&$MyStructure; //The top level array is the top parent for($ParentNum=0;$ParentNum<$NumDirectories;$ParentNum++) //Add the parent directories to the contents structure { $CurrentDirectory=&$CurrentDirectory[$FilePath[$ParentNum]]; //Get the next parent directory in the path list if(!isset($CurrentDirectory)) //If next parent directory does not already exist, create it $CurrentDirectory=Array(); } $CurrentDirectory[$FilePath[$NumDirectories]]=$FileInfo[1]; //Set the filename in the contents structure to its confirmation string } $Structures[$i]=$MyStructure; //Remember the structure } //Output directory differences $Root=DirDiff($Structures[0], $Structures[1]); print "Total Differences: $Root[NumDifferences]
Total Items: $Root[NumItems]
$Root[DiffString]"; function DirDiff($Dir1, $Dir2) //Returns Array(DiffString, NumItems, NumDifferences) { //Determine all the file and subdirectory names in both directories $DirectoryNames=Array(); $FileNames=Array(); foreach(Array($Dir1, $Dir2) as $CurDir) foreach($CurDir as $ItemName => $Item) if(is_array($Item)) $DirectoryNames[$ItemName]=0; else $FileNames[$ItemName]=0; //Sort directory and file lists into a natural case order $DirectoryNames=array_keys($DirectoryNames); $FileNames=array_keys($FileNames); natcasesort($DirectoryNames); natcasesort($FileNames); //Output list of items (directories then files) within this directory $NumDifferences=0; $NumItems=0; $RetVal=''; //End a directory listing return Array('DiffString'=>$RetVal, 'NumItems'=>$NumItems, 'NumDifferences'=>$NumDifferences); } ?>