Chinaunix首页 | 论坛 | 博客
  • 博客访问: 239970
  • 博文数量: 108
  • 博客积分: 3045
  • 博客等级: 中校
  • 技术积分: 1162
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-19 18:26
文章分类

全部博文(108)

分类: PHP

2013-07-17 22:18:20


  1. <?php
  2. $filecounter=0;
  3. $dircounter=0;

  4. function copydir($source, $dest)
  5. {
  6.     global $filecounter;
  7.     global $dircounter;
  8.     
  9.     if(is_file($dest))
  10.     {
  11.         die("Can't build directory $dest
    "
    );
  12.     }
  13.     if(!file_exists($dest))
  14.     {
  15.         mkdir($dest);
  16.         $dircounter++;
  17.     }
  18.     
  19.     $handle=opendir($source);
  20.     readdir($handle);
  21.     readdir($handle);
  22.     
  23.     while(($file=readdir($handle))!==false)
  24.     {
  25.         $filefrom=$source.DIRECTORY_SEPARATOR.$file;
  26.         
  27.         $fileto=$dest.DIRECTORY_SEPARATOR.$file;
  28.         
  29.         if(is_dir($filefrom))
  30.         {
  31.             copydir($filefrom, $fileto);
  32.         }
  33.         else
  34.         {
  35.             copy ($filefrom,$fileto);
  36.             $filecounter++;
  37.         }
  38.     }
  39.     closedir($handle);
  40.     
  41.     
  42. }



  43. copydir("phpMyAdmin", "phpAdmin");
  44. echo $filecounter."
    "
    ;
  45. echo $dircounter."
    "
    ;

  46. ?>

阅读(221) | 评论(0) | 转发(0) |
0

上一篇:$_FILES系统函数

下一篇:PHP_删除目录_code

给主人留下些什么吧!~~