note 61408 added to function.copy

From: Date: Thu, 02 Feb 2006 19:06:46 +0000
Subject: note 61408 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-102882@lists.php.net to get a copy of this message
I have programmed a really nice program that remotely lets you manage files as if you have direct access to them (http://sourceforge.net/projects/filemanage/). I have a bunch of really handy functions to do just about anything to files or directories. I know there are others like it, but here is the function I made for this program to copy directories; it will likely need tweaking to work as a standalone script, since it relies of variables set by my program (eg: loc1 -- which dynamically changes in my program): <?PHP // loc1 is the path on the computer to the base directory that may be moved define('loc1', 'C:/Program Files/Apache Group/Apache/htdocs', true); // copy a directory and all subdirectories and files (recursive) // void dircpy( str 'source directory', str 'destination directory' [, bool 'overwrite existing files'] ) function dircpy($source, $dest, $overwrite = false){ if($handle = opendir(loc1 . $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(loc1 . $path)){ if(!is_file(loc1 . $dest . '/' . $file) || $overwrite) if(!@copy(loc1 . $path, loc1 . $dest . '/' . $file)){ echo '<font color="red">File ('.$path.') could not be copied, likely a permissions problem.</font>'; } } elseif(is_dir(loc1 . $path)){ if(!is_dir(loc1 . $dest . '/' . $file)) mkdir(loc1 . $dest . '/' . $file); // make subdirectory before subdirectory is copied dircpy($path, $dest . '/' . $file, $overwrite); //recurse! } } } closedir($handle); } } // end of dircpy() ?> This new function will be in 0.9.7 (the current release of File Manage) which has just been released 2/2/06. Hope this helps some people. ---- Server IP: 64.71.164.2 Probable Submitter: 67.181.154.141 ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61408 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61408&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61408&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61408&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61408&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61408&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61408&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61408&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61408&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102882) next »