Skip to content

Instantly share code, notes, and snippets.

@akalongman
Created March 7, 2014 08:43
Show Gist options
  • Save akalongman/9407810 to your computer and use it in GitHub Desktop.
Save akalongman/9407810 to your computer and use it in GitHub Desktop.
Copy folder recursively
$path = 'path/to/src';
$dest = 'path/to/dest';
foreach (
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST) as $item
) {
if ($item->isDir()) {
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
} else {
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment