note 30085 deleted from function.copy by betz

From: Date: Thu, 06 Mar 2003 11:09:56 +0000
Subject: note 30085 deleted from function.copy by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-44933@lists.php.net to get a copy of this message
Here is a function that will recursively copy a file into every directory within a specified directory, unless the directory is in an optional third parameter, an array with a list of directory names to skip. It will also print whether it copied each item it expected to. <?php function copyintodir ($file, $dir, $skip = array('')) { if (count($skip) == 1) { $skip = array("$skip"); } if (!@($thisdir = opendir($dir))) { print "could not open $dir<br />"; return; } while ($item = readdir($thisdir) ) { if (is_dir("$dir/$item") && (substr("$item", 0, 1) != '.') && (!in_array($item, $skip))) { copyintodir($file, "$dir/$item", $skip); } } if (@copy($file, "$dir/$file")) { print "Copied $file into $dir/$file<br />\n"; } else { print "Could not copy $file into $dir/$file<br />\n"; } } ?> You can call it using a function call such as this: copyintodir ('index.php', '.', 'images');

« previous php.notes (#44933) next »