skip directory feature
This commit is contained in:
parent
acae61f9d8
commit
01f520509e
|
@ -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,12 +99,16 @@ 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) {
|
||||||
|
|
||||||
|
$currentDirectory = dirname($item->getPathName());
|
||||||
|
if ($skipDirectory !== $currentDirectory) {
|
||||||
if ($item->isDir()) {
|
if ($item->isDir()) {
|
||||||
@mkdir($destination.DS.$iterator->getSubPathName());
|
@mkdir($destination.DS.$iterator->getSubPathName());
|
||||||
} else {
|
} else {
|
||||||
copy($item, $destination.DS.$iterator->getSubPathName());
|
copy($item, $destination.DS.$iterator->getSubPathName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue