/**
 *遍历地删除或显示文件目录
 *@param string $dir 文件目录名
 *@param boolean $bool 控制是删除文件还是输出文件名:true--删除,false---输出
 */
function _scandir($dir, $bool)
{
    foreach (glob($dir . '/*') as $k1 => $v1) {
        if ($v1 === '.' || $v1 === '..') {
            break;
        }
        if (is_dir($v1)) {
            //echo $k1 . '---' . $v1 . '<br />';
            _scandir($v1, true);
        } else {
            $bool == true ? unlink($v1) : (print $v1 . '<br />');
        }
    }
}
Beispiel #2
0
function recurse($path, $callback)
{
    $path = _realpath($path);
    foreach (_scandir($path) as $file) {
        if ($file == '.' or $file == '..') {
            continue;
        }
        $realfile = _realpath("{$path}/{$file}");
        if (_is_dir($realfile)) {
            recurse($realfile, $callback);
        } else {
            $callback($realfile);
        }
    }
    $callback($path);
}
Beispiel #3
0
 public function setPath($path)
 {
     // Update
     if ($path == '*') {
         $path = $this->_path;
     }
     $path = _realpath($path);
     if (_file_exists($path) and _is_dir($path)) {
         if (_is_readable($path)) {
             $this->_path = $path;
             $this->_tree = _scandir($this->_path);
             $this->_size = count($this->_tree);
             return $this->_path;
         } else {
             throw new Exception("Can't read dir: {$path}");
         }
     } else {
         throw new Exception("Not a dir: {$path}");
     }
 }