Exemplo n.º 1
0
 /**
  * Find empty directories
  * 
  * @param string $dir An absolute path to the directory to search
  * @param integer $options Iterator options
  * @return array<string>
  */
 public static function emptyDirectories($dir, $options = 0)
 {
     $ret = [];
     $iterator = self::getIterator($dir, $options);
     foreach ($iterator as $file) {
         if ($iterator->isDot() === false && $file->isDir() && ($path = $file->getRealPath()) && !array_key_exists($path, $ret) && Dir::isEmpty($path)) {
             $ret[$path] = 1;
         }
     }
     return array_keys($ret);
 }
Exemplo n.º 2
0
 /**
  * Recursively copy a directory
  *
  * @param string $source The absolute directory path to copy from
  * @param string $dest The absolute directory path to copy to
  * @param octal $mode Permissions for newly created directories
  * @return boolean|string
  * @return boolean:true The copy was successful
  * @return string An error message describing the failure
  */
 public static function copy($source, $dest, $mode = 0775)
 {
     if (($test = Dir::prepare($dest, $mode)) !== true) {
         return "failed to copy '{$source}' to '{$dest}'; {$test}";
     } else {
         if (Dir::isEmpty($dest) === false) {
             return "failed to copy '{$source}'; '{$dest}' is not empty";
         }
     }
     $iterator = Find::getIterator($source, Find::RECURSIVE);
     foreach ($iterator as $file) {
         $destPath = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
         if ($file->isDir()) {
             mkdir($destPath, $mode);
         } else {
             copy($file, $destPath);
         }
     }
     return true;
 }