The code below is to copy the files from one dir to another. here in the function dircopy $verbose is set to false. and later a action is done when the $verbose is true. in between there are no actions that are setting the $verbose to true... when do this $verbose is changing to true ?... any idea ?? Please advise.....

function dircopy($srcdir, $dstdir, $verbose = false) {
  $num = 0;
  if(!is_dir($dstdir)) mkdir($dstdir);
  if($curdir = opendir($srcdir)) {
   while($file = readdir($curdir)) {
     if($file != '.' && $file != '..') {
       $srcfile = $srcdir . '\\' . $file;
       $dstfile = $dstdir . '\\' . $file;
       if(is_file($srcfile)) {
         if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1;
         if($ow > 0) {
           if($verbose) echo "Copying '$srcfile' to '$dstfile'...";
           if(copy($srcfile, $dstfile)) {
             touch($dstfile, filemtime($srcfile)); $num++;
             if($verbose) echo "OK\n";
           else echo "Error: File '$srcfile' could not be copied!\n";
       else if(is_dir($srcfile)) {
         $num += dircopy($srcfile, $dstfile, $verbose);
  return $num;


10 Years
Discussion Span
Last Post by jblacdao

Actually $verbose is just used as a flag once you call the function. Its set to false by default, meaning while copying the files it won't printout anything as files are being copied. However, if you supply a true value once you called this function like

dircopy($src, $dest, true);

as files are copied, you will receive a printout everytime a file is successfully copied

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.