From 7fe54067201e2837862d2692a01b32e5b5249ee7 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Mon, 27 Jun 2011 06:03:21 +0000 Subject: [PATCH] + add a file of class. --- lib/file/file.class.php | 119 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 lib/file/file.class.php diff --git a/lib/file/file.class.php b/lib/file/file.class.php new file mode 100644 index 0000000000..b25fda0987 --- /dev/null +++ b/lib/file/file.class.php @@ -0,0 +1,119 @@ +copyDir($nextFrom, $nextTo); + } + } + return $copiedFiles; + } + + /** + * Remove a dir. + * + * @param string $dir + * @access public + * @return bool + */ + public function removeDir($dir) + { + $dir = realpath($dir) . '/'; + + if(!is_writable($dir)) return false; + if(!is_dir($dir)) return true; + + $entries = scandir($dir); + foreach($entries as $entry) + { + if($entry == '.' or $entry == '..' or $entry == '.svn') continue; + + $fullEntry = $dir . $entry; + if(is_file($fullEntry)) + { + unlink($fullEntry); + } + else + { + $this->removeDir($fullEntry); + } + } + if(!@rmdir($dir)) return false; + return true; + } + + /** + * Get files under a directory recursive. + * + * @param string $dir + * @param array $exceptions + * @access private + * @return array + */ + public function readDir($dir, $exceptions = array()) + { + static $files = array(); + + if(!is_dir($dir)) return $files; + + $dir = realpath($dir) . '/'; + $entries = scandir($dir); + + foreach($entries as $entry) + { + if($entry == '.' or $entry == '..' or $entry == '.svn') continue; + if(in_array($entry, $exceptions)) continue; + + $fullEntry = $dir . $entry; + if(is_file($fullEntry)) + { + $files[] = $dir . $entry; + } + else + { + $nextDir = $dir . $entry; + $this->readDir($nextDir); + } + } + return $files; + } +}