3

dircopy

dircopy
SYNOPSIS

dircopy($from, $to, $mode = 0777)

CODE
  1. function dircopy($from, $to, $mode = 0777) {
  2.     if (!is_dir($from)) {
  3.         return false;
  4.     }
  5.  
  6.     if (!is_dir($to)) {
  7.         if (!@mkdir($to)) {
  8.             return false;
  9.         }
  10.     }
  11.  
  12.     dircopyaux($from, $to, $mode);
  13.  
  14.     return true;
  15. }
  16.  
  17. function dircopyaux($from, $to, $mode) {
  18.     $handle = opendir($from);
  19.     while (($file = readdir($handle)) !== false) {
  20.         if ($file == '.' || $file == '..') {
  21.             continue;
  22.         }
  23.         $frompath = $from . DIRECTORY_SEPARATOR . $file;
  24.         $topath = $to . DIRECTORY_SEPARATOR . $file;
  25.         if (is_link($frompath)) {
  26.             if (file_exists($topath)) {
  27.                 unlink($topath);
  28.             }
  29.             symlink(readlink($frompath), $topath);
  30.         }
  31.         else if (is_file($frompath)) {
  32.             copy($frompath, $topath);
  33.         }
  34.         else if (is_dir($frompath)) {
  35.             if (!is_dir($topath)) {
  36.                 mkdir($topath, $mode);
  37.             }
  38.             dircopyaux($frompath, $topath, $mode);
  39.         }
  40.     }
  41.     closedir($handle);
  42. }
SEE ALSO

dirclear, dirlist

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].