note 105024 added to function.copy

From: Date: Fri, 22 Jul 2011 16:25:15 +0000
Subject: note 105024 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-181794@lists.php.net to get a copy of this message
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> ---- Server IP: 69.147.83.197 Probable Submitter: 99.137.201.206 ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- https://master.php.net/note/edit/105024 Del: integrated -- https://master.php.net/note/delete/105024/integrated Del: useless -- https://master.php.net/note/delete/105024/useless Del: bad code -- https://master.php.net/note/delete/105024/bad+code Del: spam -- https://master.php.net/note/delete/105024/spam Del: non-english -- https://master.php.net/note/delete/105024/non-english Del: in docs -- https://master.php.net/note/delete/105024/in+docs Del: other reasons-- https://master.php.net/note/delete/105024 Reject -- https://master.php.net/note/reject/105024 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181794) next »