function cp($src, $dest, $as_child = false, $include_regex = '', $exclude_regex = '', $include_hidden = false) { if (!is_dir($src)) return throw_error(new IOException('no such a directory', array('dir' => $src))); Fs :: mkdir($dest); $src = Fs :: normalizePath($src); $dest = Fs :: normalizePath($dest); $separator = Fs :: separator(); if($as_child) { $separator_regex = preg_quote($separator); if (preg_match( "#^.+{$separator_regex}([^{$separator_regex}]+)$#", $src, $matches)) { Fs :: _doMkdir($dest . $separator . $matches[1], 0777); $dest .= $separator . $matches[1]; } else return false; } $items = Fs :: find($src, 'df', $include_regex, $exclude_regex, false, $include_hidden); $total_items = $items; while (count($items) > 0) { $current_items = $items; $items = array(); foreach ($current_items as $item) { $full_path = $src . $separator . $item; if (is_file( $full_path)) copy($full_path, $dest . $separator . $item); elseif (is_dir( $full_path)) { Fs :: _doMkdir($dest . $separator . $item, 0777); $new_items = Fs :: find($full_path, 'df', $include_regex, $exclude_regex, $item, $include_hidden); $items = array_merge($items, $new_items); $total_items = array_merge($total_items, $new_items); unset($new_items); } } } if($total_items) clearstatcache(); return $total_items; }