note 61408 deleted from function.copy by aidan

From: Date: Wed, 15 Apr 2009 12:30:43 +0000
Subject: note 61408 deleted from function.copy by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153297@lists.php.net to get a copy of this message
Note Submitter: bobbfwed at comcast dot net ---- 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.

« previous php.notes (#153297) next »