function copy_module_file($path,$newp){
if(!is_dir($newp)){
mkdir($newp);
}
if (file_exists($path)){
if(is_file($path)){
copy($path,$newp);
} else{
$handle = opendir($path);
while (($file = readdir($handle))!='') {
if (($file!=".") && ($file!="..") && ($file!="")){
if (is_dir("$path/$file")){
copy_module_file("$path/$file","$newp/$file");
} else{
copy("$path/$file","$newp/$file");
}
}
}
closedir($handle);
}
}
}这段php代码是我程序中的,一个复制些个文件夹下的目录到另一个文件夹下,里面有好多目录,比如该文件夹里面有1-100个目录名字分别是1-100,我想让: 10,30,35,36 这几目录不被复制那么,这段php需要怎么改一下,我是新手,希望得到高手指点!PHPcopy 

解决方案 »

  1.   

    $ex = array('10', '30', '35', '36'); //不复制的目录
    function copy_module_file($path,$newp, $ex=array()){ //注意这里
        if(!is_dir($newp)){
            mkdir($newp);
        }
        if (file_exists($path)){
            if(is_file($path)){
                copy($path,$newp);
            } else{
                $handle = opendir($path);
                while (($file = readdir($handle))!='') {
                    if (($file!=".") && ($file!="..") && ($file!="")){
                        if (is_dir("$path/$file")){
                            if(in_array($file, $ex)) continue; //注意这里
                            copy_module_file("$path/$file","$newp/$file");
                        } else{
                            copy("$path/$file","$newp/$file");
                        }
                    }
                }
                closedir($handle);
            }
        }
    }