Location: PHPKode > scripts > Directory Match > directory-match/dirMatch.php
<?
/*
Author : Muhammmad Sohail Khan
Date Created :September 20 2006
Email: hide@address.com,hide@address.com

Hope u will coment and email me.......

also need some good suggestion....

Take Care and Bye

*/
// $pathDir1 =  path of ur folder where u want put ur file (iamge or text files) example "folder1/subfolder1";
// $pathDir2 = path of ur folder with wich u wana compare ur pathDir1 folder and want to copy the missin files there example "folder2/subfolder2";

class matchDir {


public $pathDir1 ;

public $pathDir2 ;

public $f2 ;

public $file2 ;

public $missingCounter = 0 ;

public $counter = 0 ;

function matchDir($pathDir1 , $pathDir2)
{

	$this -> pathDir1 = $pathDir1 ;
	
	$this -> pathDir2 = $pathDir2 ;
	
	$this -> f2 = opendir($this -> pathDir2);	

}

function match()
{
	while($this -> file2 = readdir($this -> f2))
	{
		
		if(is_file($this -> pathDir2.$this -> file2))
		{	
			if (!file_exists($this -> pathDir1.$this -> file2))
			{
	
				echo $this -> file2.'Not Exists';
	
				echo "<br>";
	
				$f3 = fopen("imageText.txt",'a+') ;
				
				fwrite($f3,$this -> file2."<br>");
				
				$this -> missingCounter++;
				
				fclose($f3);
	
			if (copy($this -> pathDir2.$this -> file2 , $this -> pathDir1.$this -> file2))
			{
	
				echo "copied <br>";
	
			}else{
	
				echo "faile to copy image <br>";
	
			}
				
			} else
			{
				echo $this -> file2.' Exists ';
	
				echo "<br>";
			}
		}
	
		$this -> counter++ ;
	}

	closedir($this -> f2);

	echo $this -> counter .'  Total Files <br>'  ;
	
	echo $this -> missingCounter .'  Missing Total Files <br>'  ;
}

	

}

$pathDir1 = "targetFolder/";

$pathDir2 = "sourceFolder/";

$obj =new matchDir($pathDir1 , $pathDir2);

$obj -> match();

?>
Return current item: Directory Match