天天看点

改进版PHP复制文件夹及其内容

<?php
           

function copydir( s o u r c e = &quot; s o u r c e s &quot; , source=&quot;sources&quot;, source="sources",dest=“dog”)

{

if (!file_exists(KaTeX parse error: Expected '}', got 'EOF' at end of input: …{ mkdir(dest);

}

h a n d l e = o p e n d i r ( handle = opendir( handle=opendir(source);//打开sources文件夹

while (( i t e m = r e a d d i r ( item = readdir( item=readdir(handle)) !== false) {//读取文件夹

if ($item == ‘.’ || $item == ‘…’){

continue;

}

$_source = $source . ‘/’ . $item;

$_dest = $dest . ‘/’ . i t e m ; i f ( i s f i l e ( item; if (is_file( item;if(isf​ile(_source)) //文件

{

copy($_source, KaTeX parse error: Expected 'EOF', got '}' at position 17: …dest); }̲ …_source)) { //文件夹

copydir($_source, KaTeX parse error: Expected 'EOF', got '}' at position 21: …); }̲ } clos…handle);

}

copydir();

?>

php