From b02b44d1da7e9ddd7a341d29a597accfbb78155c Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 22 Aug 2025 15:19:06 +0200 Subject: =?UTF-8?q?Am=C3=A9lioration=20de=20copy=5Fdirectory.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/copy_directory.php | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/bin/copy_directory.php b/bin/copy_directory.php index 2c001c0..20e4821 100644 --- a/bin/copy_directory.php +++ b/bin/copy_directory.php @@ -1,11 +1,18 @@ isDir()) { - mkdir($destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); - } else { - copy($item, $destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); + foreach($iterator as $item){ + $targetPath = $destination . DIRECTORY_SEPARATOR . $iterator->getSubPathName(); + if($item->isDir()){ + if(!is_dir($targetPath)){ + mkdir($targetPath, 0755); + } + } + else{ + copy($item, $targetPath); // copy() écrase la cible, c'est ce qu'on veut } } } +if ($argc != 3){ // nombre de paramètres + fwrite(STDERR, "Erreur rencontrée dans bin/copy_directory.php. Usage:\nphp bin/copy_directory.php \n"); + exit(1); +} copyDirectory($argv[1], $argv[2]); -- cgit v1.2.3