<?php
/**
* this example would list all the image files
* found in /home/user/public_html
* which do not also exist in /var/www/html
* and copy over the missing files
*/
// ----------- initialise ------------
require_once('pfpFileTree.inc.php');
$src='/home/user/public_html';
$dest='/var/www/html'; // NB class wil sort out trailing dir seperators
$t=new pfpFileTree($src);
$t->ignoreNoDescend=true; // ignore some errors
$t->caseSensitive=false; // used for globbing only
// --------- grab images -----------
$t->readTree(array('name'=>'*.jpg'));
$t->readTree(array('name'=>'*.png'));
$t->readTree(array('name'=>'*.gif'));
// note it would have been much more efficient to...
// $t->readTree(array('name'=>'{*jpg,*.png,*.gif}');
// $t->data is now populated with a list of all image files
$t->ls();
// --------- compare with dest ---------
$t->compareTree($dest);
$files=$t->filter(array('cmp'=>2)); // just find the missing files
if ($t->writeTo($dest)===false) {
print "Copy would have failed for: ";
$nocopy=$t->subset(array('can_w'=>false));
$nocopy->ls();
} else {
print "files copied";
}
|