PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ePHP/libraries/Dir.class.php

http://php-framework-ephp.googlecode.com/
PHP | 98 lines | 59 code | 8 blank | 31 comment | 18 complexity | e14735d3d67ac5a6b48eb7ea7c4ac538 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. +------------------------------------------------------------------------------
  4. * ?????
  5. +------------------------------------------------------------------------------
  6. * @version 3.0
  7. * @author WangXian
  8. * @package libraries
  9. * @email admin@loopx.cn
  10. * @creation_date 2011-1-1 ??05:59:48
  11. * @last_modified 2011-06-04 22:21:03
  12. +------------------------------------------------------------------------------
  13. */
  14. class Dir
  15. {
  16. /**
  17. * ????
  18. * ???????index.php?????????
  19. * @param string $source_dir ???index.php???
  20. * @param boolean $subdir ?????,true???false???
  21. * @return mixed
  22. */
  23. public static function map($source_dir, $subdir = true)
  24. {
  25. if ( true == ($fp = opendir($source_dir)) )
  26. {
  27. $source_dir = rtrim($source_dir, '/').'/';
  28. $filedata = array();
  29. while (false !== ($file = readdir($fp)))
  30. {
  31. if ( $file == '.' OR $file == '..' ) continue;
  32. if ($subdir && is_dir($source_dir.$file))
  33. {
  34. $temp_array = array();
  35. $temp_array = self::map($source_dir.$file.'/', $subdir);
  36. $filedata[$file] = $temp_array;
  37. }
  38. else
  39. {
  40. $filedata[] = $file;
  41. }
  42. }
  43. closedir($fp);
  44. return $filedata;
  45. }
  46. else
  47. {
  48. return false;
  49. }
  50. }
  51. /**
  52. * ????????
  53. * @param string $dir
  54. * @return boolean true???false???
  55. */
  56. public static function isEmpty($dir)
  57. {
  58. $handle = opendir($dir);
  59. $i = 0;
  60. while( false !== ($file = readdir($handle)) ) $i++;
  61. closedir($handle);
  62. if($i >= 2) return false;
  63. else return true;
  64. }
  65. /**
  66. * ????????????
  67. * @param string $dir
  68. * @return boolean
  69. */
  70. public static function deleteDir($dir)
  71. {
  72. $d = dir($dir);
  73. while( false !== ($entry = $d->read()) )
  74. {
  75. if($entry == '.' || $entry == '..') continue;
  76. $currele = $d->path.'/'.$entry;
  77. if(is_dir($currele))
  78. {
  79. if(self::isEmpty($currele)) rmdir($currele);
  80. else self::deleteDir($currele);
  81. }
  82. else unlink($currele);
  83. }
  84. $d->close();
  85. rmdir($dir);
  86. return true;
  87. }
  88. }
  89. /* End of file Dir.class.php */
  90. /* Location: ./_framework/libraries/Dir.class.php */