note 105024 deleted from function.copy by danbrown

From: Date: Mon, 25 Jul 2011 12:29:49 +0000
Subject: note 105024 deleted from function.copy by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181837@lists.php.net to get a copy of this message
Note Submitter: michael dot lee dot baker at gmail dot com ---- I added on to Cory at Veck Dot's code to move all files that are nested into one top level directory - in this case it was images. <pre> define('DS', DIRECTORY_SEPARATOR); // I always use this short form in my code. function copy_r( $path, $dest ) { if( is_dir($path) ) { @mkdir( $dest ); $objects = scandir($path); if( sizeof($objects) > 0 ) { foreach( $objects as $file ) { if( $file == "." || $file == ".." ) continue; // go on if( is_dir( $path.DS.$file ) ) { $images = scandir($path.DS.$file); foreach( $images as $image ){ if( $image == "." || $image == ".." ) continue; if( !is_dir( $image ) ){ copy_r( $path.DS.$file.DS.$image, $dest.DS.$image ); echo $image ."<br />"; } } } else { copy( $path.DS.$file, $dest.DS.$file ); } } } return true; } elseif( is_file($path) ) { return copy($path, $dest); } else { return false; } } </pre>

« previous php.notes (#181837) next »