note 104020 added to function.copy

From: Date: Tue, 17 May 2011 18:13:43 +0000
Subject: note 104020 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-179835@lists.php.net to get a copy of this message
Here is a simple script that I use for removing and copying non-empty directories. Very useful when you are not sure what is the type of a file. I am using these for managing folders and zip archives for my website plugins. <?php // 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); } ?> Cheers! ---- Server IP: 69.147.83.197 Probable Submitter: 138.251.95.1 (proxied: 138.251.241.49) ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- https://master.php.net/note/edit/104020 Del: integrated -- https://master.php.net/note/delete/104020/integrated Del: useless -- https://master.php.net/note/delete/104020/useless Del: bad code -- https://master.php.net/note/delete/104020/bad+code Del: spam -- https://master.php.net/note/delete/104020/spam Del: non-english -- https://master.php.net/note/delete/104020/non-english Del: in docs -- https://master.php.net/note/delete/104020/in+docs Del: other reasons-- https://master.php.net/note/delete/104020 Reject -- https://master.php.net/note/reject/104020 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179835) next »