Skip to content

Instantly share code, notes, and snippets.

@TheRatG
Created February 2, 2016 09:50
Show Gist options
  • Save TheRatG/75db3895d3f345df0697 to your computer and use it in GitHub Desktop.
Save TheRatG/75db3895d3f345df0697 to your computer and use it in GitHub Desktop.
symfony copy dir
$fileSystem = new Filesystem();
$fileSystem->mkdir($target);
$directoryIterator = new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $item) {
if ($item->isDir()) {
$targetDir = $target.DIRECTORY_SEPARATOR.$iterator->getSubPathName();
$fileSystem->mkdir($targetDir);
} else {
$targetFilename = $target.DIRECTORY_SEPARATOR.$iterator->getSubPathName();
$fileSystem->copy($item, $targetFilename);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment