note 70238 deleted from function.copy by danbrown

From: Date: Mon, 02 Mar 2009 17:54:54 +0000
Subject: note 70238 deleted from function.copy by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151358@lists.php.net to get a copy of this message
Note Submitter: SkyEye ---- <?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; } ?>

« previous php.notes (#151358) next »