note 38966 added to function.copy

From: Date: Tue, 13 Jan 2004 16:54:19 +0000
Subject: note 38966 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-63464@lists.php.net to get a copy of this message
An improvement of the example of torrmal at yahoo dot com published at 04-Jul-2003 11:05 (to avoid the warning if file exists) function cp($wf, $wto){ // it moves $wf to $wto if (!file_exists($wto)){//the improvement mkdir($wto,0777); } $arr=ls_a($wf); foreach ($arr as $fn){ if($fn){ $fl="$wf/$fn"; $flto="$wto/$fn"; if(is_dir($fl)) cp($fl,$flto); else copy($fl,$flto); } } } /////////////////////////////////////////////////// /// ls_a function//////////////////////// // This function lists a directory. // ANd is needed for the cp function. function ls_a($wh){ if ($handle = opendir($wh)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." ) { if(!$files) $files="$file"; else $files="$file\n$files"; } } closedir($handle); } $arr=explode("\n",$files); for($i=0;$i<count($arr);$i++){ echo "<br>$arr[$i]"; } return $arr; } ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38966 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38966&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38966&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63464) next »