选择语言 :

 Core_File::copy_dir

复制目录下的所有目录和文件到另外一个目录

array($dook,$doerror) Core_File::copy_dir( string $fromdir , string $todir [, boolean $autocoverageold = bool true , string $storage = string(7) "default" ] )

参数列表

参数 类型 描述 默认值
$fromdir string 源文文件目录
$todir string 目标文件目录
$autocoverageold boolean 是否覆盖已有文件,true覆盖,false跳过 bool true
$storage string 物理存储组,不传则为默认 string(7) "default"
返回值
  • array($dook,$doerror)
File: ./core/classes/file.class.php
public static function copy_dir($fromdir, $todir, $autocoverageold = true , $storage = 'default')
{
    $fromdir = rtrim($fromdir,'\\/').DS;
    $todir   = rtrim($todir,'\\/')  .DS;

    if ( $fromdir==$todir ) return array(0,0);

    $info1 = File::check_and_get_path($fromdir);
    $info2 = File::check_and_get_path($todir);

    if (File::can_do_run($storage))
    {
        if (!is_dir($fromdir)) return array(0, 0);

        # 完成数
        $donum = array(0, 0);

        if (!is_dir($todir))
        {
            # 创建目标目录
            File::create_dir($todir,false,$storage);
        }

        # 列出目录中当前级别的目录和文件
        $files = glob($fromdir . '*');

        foreach ($files as $file)
        {
            # 目标文件
            $tofile = $todir . basename($file);

            if (is_dir($file))
            {
                # 如果当前是目录,则移动目录

                # 移动目录
                $donum2 = File::copy_dir($file, $tofile, $autocoverageold, $storage);
                if ($donum2)
                {
                    $donum[0] += $donum2[0];
                    $donum[1] += $donum2[1];
                }
            }
            else
            {
                # 文件
                if ($autocoverageold && file_exists($tofile))
                {
                    //覆盖已有文件
                    @unlink($tofile);
                }

                if (@copy($file, $tofile))
                {
                    $donum[0]++;
                }
                else
                {
                    $donum[1]++;
                }
            }
        }

        return $donum;
    }
    else
    {
        return File::call_http_host($storage,'file/copy_dir', $info1[0], $info1[1], $info2[0], $info2[1], $autocoverageold);
    }
}