note 68377 added to function.copy

From: Date: Tue, 25 Jul 2006 05:38:01 +0000
Subject: note 68377 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-115114@lists.php.net to get a copy of this message
just a quick note to add to teh great function by: bobbfwed at comcast dot net this little version has the path not in a define but as a function parameter and also creates the destination directory if it is not already created. <?php // copy a directory and all subdirectories and files (recursive) // void dircpy( str 'source directory', str 'destination directory' [, bool 'overwrite existing files'] ) function dircpy($basePath, $source, $dest, $overwrite = false){ if(!is_dir($basePath . $dest)) //Lets just make sure our new folder is already created. Alright so its not efficient to check each time... bite me mkdir($basePath . $dest); if($handle = opendir($basePath . $source)){ // if the folder exploration is sucsessful, continue while(false !== ($file = readdir($handle))){ // as long as storing the next file to $file is successful, continue if($file != '.' && $file != '..'){ $path = $source . '/' . $file; if(is_file($basePath . $path)){ if(!is_file($basePath . $dest . '/' . $file) || $overwrite) if(!@copy($basePath . $path, $basePath . $dest . '/' . $file)){ echo '<font color="red">File ('.$path.') could not be copied, likely a permissions problem.</font>'; } } elseif(is_dir($basePath . $path)){ if(!is_dir($basePath . $dest . '/' . $file)) mkdir($basePath . $dest . '/' . $file); // make subdirectory before subdirectory is copied dircpy($basePath, $dest . '/' . $file, $overwrite); //recurse! } } } closedir($handle); } } // end of dircpy() //Usage dircpy('C:/Program Files/Apache Group/Apache2/htdocs', "/testfolder", "/testfolder2", false); ?> ---- Server IP: 66.207.199.35 Probable Submitter: 70.83.141.176 ---- X-Spam-Status: No, hits=3.4 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_FONTCOLOR_UNKNOWN,HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- http://master.php.net/note/edit/68377 Del: integrated -- http://master.php.net/note/delete/68377/integrated Del: useless -- http://master.php.net/note/delete/68377/useless Del: bad code -- http://master.php.net/note/delete/68377/bad+code Del: spam -- http://master.php.net/note/delete/68377/spam Del: non-english -- http://master.php.net/note/delete/68377/non-english Del: in docs -- http://master.php.net/note/delete/68377/in+docs Del: other reasons-- http://master.php.net/note/delete/68377 Reject -- http://master.php.net/note/reject/68377 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115114) next »