Dir::copyDir PHP Method

copyDir() public method

+---------------------------------------------------------- 复制目录 +---------------------------------------------------------- +---------------------------------------------------------- +----------------------------------------------------------
public copyDir ( $source, $destination )
    public function copyDir($source, $destination)
    {
        if (is_dir($source) == false) {
            exit('The Source Directory Is Not Exist!');
        }
        if (is_dir($destination) == false) {
            mkdir($destination, 0700);
        }
        $handle = opendir($source);
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..') {
                is_dir("{$source}/{$file}") ? Dir::copyDir("{$source}/{$file}", "{$destination}/{$file}") : copy("{$source}/{$file}", "{$destination}/{$file}");
            }
        }
        closedir($handle);
    }

Usage Example

 public function install()
 {
     define("INSTALL", true);
     import("Dir");
     //安装目录
     $path = APP_PATH . C("APP_GROUP_PATH") . DIRECTORY_SEPARATOR . $this->config['module'] . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR;
     $Dir = new Dir();
     //SQL文件
     if (file_exists($path . $this->config['module'] . '.sql')) {
         $sql = file_get_contents($path . $this->config['module'] . '.sql');
         $sql_split = $this->sql_split($sql, C("DB_PREFIX"));
         $db = M('');
         if (is_array($sql_split)) {
             foreach ($sql_split as $s) {
                 $db->execute($s);
             }
         }
     }
     //Extention,菜单添加
     if (file_exists($path . 'Extention.inc.php')) {
         @(include $path . 'Extention.inc.php');
     }
     //前台模板
     if (file_exists($path . "Template" . DIRECTORY_SEPARATOR)) {
         $Dir->copyDir($path . "Template", $this->templatePath);
     }
     D("Module")->add(array("module" => $this->config['module'], "name" => $this->config['modulename'], "iscore" => 0, "version" => $this->config['version'], "description" => $this->config['introduce'], "disabled" => 1, "installdate" => date("Y-m-d"), "updatedate" => date("Y-m-d")));
     return true;
 }
All Usage Examples Of Dir::copyDir