12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace file;
- class DirHelper
- {
-
- public static function makeDir($path)
- {
- if (!file_exists($path)) {
- $mk = @mkdir($path, 0777, true);
- @chmod($path, 0777);
- }
- return true;
- }
-
- public static function delDir($dir)
- {
- if (file_exists($dir)) {
- $mydir = dir($dir);
- while (false !== ($file = $mydir->read())) {
- if ($file != "." && $file != "..") {
- $path = $dir . DS . $file;
- is_dir($path) ? self::delDir($path) : @unlink($path);
- }
- }
- $mydir->close();
- @rmdir($dir);
- }
- }
-
- public static function copyDir($source, $dest, $cover = true)
- {
- if (!file_exists($dest)) self::makeDir($dest);
- $handle = opendir($source);
- while (($item = readdir($handle)) !== false) {
- if ($item == '.' || $item == '..') continue;
- $_source = $source . DS . $item;
- $_dest = $dest . DS . $item;
- if (is_dir($_source)) {
- self::copyDir($_source, $_dest, $cover);
- } else if (is_file($_source)) {
- if ($cover || (!$cover && !file_exists($_dest))) {
- copy($_source, $_dest);
- }
- }
- }
- closedir($handle);
- }
-
- public static function scanDirs($path)
- {
- global $result;
- $files = scandir($path);
- foreach ($files as $file) {
- if ($file != '.' && $file != '..') {
- if (is_dir($path . '/' . $file)) {
- $result[] = $path . '/' . $file;
- self::scanDirs($path . '/' . $file);
- } else {
- $result[] = $path . '/' . $file;
- }
- }
- }
- return $result;
- }
- }
|