-
-
Save akalongman/9407810 to your computer and use it in GitHub Desktop.
Copy folder recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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