skip directory feature

This commit is contained in:
floppy0 2018-03-07 15:43:41 +01:00
parent acae61f9d8
commit 01f520509e
1 changed files with 10 additions and 6 deletions

View File

@ -78,7 +78,7 @@ class Filesystem {
// If the destination directory not exists is created // If the destination directory not exists is created
// $source = /home/diego/example or /home/diego/example/ // $source = /home/diego/example or /home/diego/example/
// $destination = /home/diego/newplace or /home/diego/newplace/ // $destination = /home/diego/newplace or /home/diego/newplace/
public static function copyRecursive($source, $destination) public static function copyRecursive($source, $destination, $skipDirectory=false)
{ {
$source = rtrim($source, DS); $source = rtrim($source, DS);
$destination = rtrim($destination, DS); $destination = rtrim($destination, DS);
@ -99,11 +99,15 @@ class Filesystem {
foreach ($iterator = new RecursiveIteratorIterator( foreach ($iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST) as $item) { RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir()) {
@mkdir($destination.DS.$iterator->getSubPathName()); $currentDirectory = dirname($item->getPathName());
} else { if ($skipDirectory !== $currentDirectory) {
copy($item, $destination.DS.$iterator->getSubPathName()); if ($item->isDir()) {
} @mkdir($destination.DS.$iterator->getSubPathName());
} else {
copy($item, $destination.DS.$iterator->getSubPathName());
}
}
} }
return true; return true;