Created
February 4, 2020 10:11
-
-
Save fhdalikhan/b5e8d2141b0161b8aac4649e0d73a0c4 to your computer and use it in GitHub Desktop.
Copy folder recursively to another folder, NOT TESTED
This file contains hidden or 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
<?php | |
# | |
# UNTESTED | |
# | |
$source = __DIR__; | |
$dest= __DIR__. DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR .'copied'; | |
mkdir($dest, 0755); | |
foreach ( | |
$iterator = new \RecursiveIteratorIterator( | |
new \RecursiveDirectoryIterator($source, \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