put functions for removing and copying directories in ther own own files and added documentation.
This commit is contained in:
parent
85a1beee12
commit
f7d3b31262
|
@ -84,36 +84,6 @@ function writeBackVersion() : bool {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// removes files and non-empty directories
|
|
||||||
function rrmdir($dir) {
|
|
||||||
if (is_dir($dir)) {
|
|
||||||
$files = scandir($dir);
|
|
||||||
foreach ($files as $file)
|
|
||||||
if ($file != "." && $file != "..") rrmdir("$dir/$file");
|
|
||||||
rmdir($dir);
|
|
||||||
}
|
|
||||||
else if (file_exists($dir)) unlink($dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
// copies files and non-empty directories
|
|
||||||
function rcopy($src, $dst) {
|
|
||||||
if (file_exists($dst)) rrmdir($dst);
|
|
||||||
if (is_dir($src)) {
|
|
||||||
mkdir($dst);
|
|
||||||
$files = scandir($src);
|
|
||||||
foreach ($files as $file)
|
|
||||||
if ($file != "." && $file != "..") rcopy("$src/$file", "$dst/$file");
|
|
||||||
}
|
|
||||||
else if (file_exists($src)) copy($src, $dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Variablen zum speichern des Fortschrittes bzw. Erfolgs.
|
// Variablen zum speichern des Fortschrittes bzw. Erfolgs.
|
||||||
$download_success = false;
|
$download_success = false;
|
||||||
|
@ -298,7 +268,7 @@ if($latest_version->isNewer($current_version)) { // neue Version verfügbar?
|
||||||
$cli->sendTitle( "Kopierenvorgang Nr. ".($copy_id+1)." von ".count($copy_paths)." - $copy_name", 2 );
|
$cli->sendTitle( "Kopierenvorgang Nr. ".($copy_id+1)." von ".count($copy_paths)." - $copy_name", 2 );
|
||||||
try {
|
try {
|
||||||
|
|
||||||
rcopy($copy_source, $copy_dest);
|
\NAE\Functions\Folder\rcopy($copy_source, $copy_dest);
|
||||||
$cli->sendSuccess( "Kopiervorgang Erfolgreich!" );
|
$cli->sendSuccess( "Kopiervorgang Erfolgreich!" );
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace for Folder related classes and functions.
|
||||||
|
* @package NAE\Functions\Folder
|
||||||
|
*/
|
||||||
|
namespace NAE\Functions\Folder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursive copy a directory and its contents to another directory (overwrites existing structures).
|
||||||
|
* @param string $source Quellpfad/URL
|
||||||
|
* @param string $destination Zielpfad
|
||||||
|
*/
|
||||||
|
function rcopy(string $source, string $destination) {
|
||||||
|
|
||||||
|
if (file_exists($destination)) {
|
||||||
|
|
||||||
|
rrmdir($destination);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (is_dir($source)) {
|
||||||
|
|
||||||
|
mkdir($destination);
|
||||||
|
$files = scandir($source);
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if ($file != "." && $file != "..") {
|
||||||
|
rcopy("$source/$file", "$destination/$file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (file_exists($source)) {
|
||||||
|
|
||||||
|
copy($source, $destination);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace for Folder related classes and functions.
|
||||||
|
* @package NAE\Functions\Folder
|
||||||
|
*/
|
||||||
|
namespace NAE\Functions\Folder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursive removes a directory and its contents
|
||||||
|
* @param string $dir Target directory to be removed
|
||||||
|
*/
|
||||||
|
function rrmdir(string $dir) {
|
||||||
|
|
||||||
|
if (is_dir($dir)) {
|
||||||
|
$files = scandir($dir);
|
||||||
|
foreach ($files as $file)
|
||||||
|
if ($file != "." && $file != "..") rrmdir("$dir/$file");
|
||||||
|
rmdir($dir);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (file_exists($dir)) {
|
||||||
|
unlink($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue