protected function _dirCopy($src, $dst, $overwrite)
{
foreach (scandir($src, SCANDIR_SORT_NONE) as $item) {
if ($item === '.' || $item === '..') {
continue;
}
$srcPath = $src . '/' . $item;
$dstPath = $dst . '/' . $item;
if (is_file($srcPath)) {
if ($overwrite || !file_exists($dstPath)) {
if (!copy($srcPath, $dstPath)) {
throw new FileException('copy `:src` file to `:dst` file failed: :last_error_message', ['src' => $srcPath, 'dst' => $dstPath]);
}
}
} elseif (is_dir($srcPath)) {
$this->_dirCreate($dstPath);
if ($overwrite || !is_dir($dstPath)) {
$this->_dirCopy($srcPath, $dstPath, $overwrite);
}
} else {
break;
}
}
}