protected static function _copy($path, $dest, $options)
{
$ds = DIRECTORY_SEPARATOR;
$root = $options['childrenOnly'] ? $path : dirname($path);
$dest = rtrim($dest, $ds);
$paths = static::scan($path, $options);
foreach ($paths as $path) {
$target = preg_replace('~^' . preg_quote(rtrim($root, $ds)) . '~', '', $path);
$isDir = is_dir($path);
$dirname = $dest . $ds . ltrim($isDir ? $target : dirname($target), $ds);
if (!file_exists($dirname)) {
mkdir($dirname, $options['mode'], true);
}
if (!$isDir) {
copy($path, $dest . $ds . ltrim($target, $ds));
}
}
}