note 70238 added to function.copy

From: Date: Sun, 08 Oct 2006 02:21:25 +0000
Subject: note 70238 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-118198@lists.php.net to get a copy of this message
<?php // A function to copy files from one directory to another one, including subdirectories and // nonexisting or newer files. Function returns number of files copied. // This function is PHP implementation of Windows xcopy A:\dir1\* B:\dir2 /D /E /F /H /R /Y // Syntaxis: [$number =] dircopy($sourcedirectory, $destinationdirectory [, $verbose]); // Example: $num = dircopy('A:\dir1', 'B:\dir2', 1); function dircopy($srcdir, $dstdir, $verbose = false) { $num = 0; if(!is_dir($dstdir)) mkdir($dstdir); if($curdir = opendir($srcdir)) { while($file = readdir($curdir)) { if($file != '.' && $file != '..') { $srcfile = $srcdir . '\\' . $file; $dstfile = $dstdir . '\\' . $file; if(is_file($srcfile)) { if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1; if($ow > 0) { if($verbose) echo "Copying '$srcfile' to '$dstfile'..."; if(copy($srcfile, $dstfile)) { touch($dstfile, filemtime($srcfile)); $num++; if($verbose) echo "OK\n"; } else echo "Error: File '$srcfile' could not be copied!\n"; } } else if(is_dir($srcfile)) { $num += dircopy($srcfile, $dstfile, $verbose); } } } closedir($curdir); } return $num; } ?> ---- Server IP: 81.198.190.2 Probable Submitter: 81.198.228.214 ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- https://master.php.net/note/edit/70238 Del: integrated -- https://master.php.net/note/delete/70238/integrated Del: useless -- https://master.php.net/note/delete/70238/useless Del: bad code -- https://master.php.net/note/delete/70238/bad+code Del: spam -- https://master.php.net/note/delete/70238/spam Del: non-english -- https://master.php.net/note/delete/70238/non-english Del: in docs -- https://master.php.net/note/delete/70238/in+docs Del: other reasons-- https://master.php.net/note/delete/70238 Reject -- https://master.php.net/note/reject/70238 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118198) next »