清空指定的目录，不会删除目录本身

@param string $path 要清空的目录的路径
@param string $isfull 路径是否为完整路径
@param string $fsencoding 文件系统的编码，如不为空则会自动进行一些编码转换
976386
public static function clear_dir($path, $isfull = false, $fsencoding = '') {
        $path = strval($path);
        if ($path == '') {
            return;
        }
        if (!$isfull) {
            $path = WEB_ROOT . $path;
        }
        $path = self::conv_to($path, $fsencoding);
        if (!is_dir($path)) {
            return;
        }
        if (substr($path, -1) !== '/') {
            $path .= '/';
        }
        if ($dh = opendir($path)) {
            while (($file = readdir($dh)) !== false) {
                if ($file === '.' || $file === '..') {
                    continue;
                }
                $full = $path . $file;
                if (is_dir($full)) {
                    self::clear_dir($full, true);
                    rmdir($full);
                }
                else {
                    @unlink($full);
                }
            }
            closedir($dh);
        }
    }
544698
public static function portion($path, $init = 0, $end = 1024, $lines = false)
    {
        self::fullpath($path);

        if ($lines !== true) {
            return file_get_contents($path, false, null, $init, $end);
        }

        $i = 1;
        $output = '';

        $handle = fopen($path, 'rb');

        while (false === feof($handle) && $i <= $end) {
            $data = fgets($handle);

            if ($i >= $init) {
                $output .= $data;
            }

            ++$i;
        }

        fclose($handle);

        return $output;
    }
94606
public function clean($path)
    {
        $tokens = [];
        $path = $this->cleanPath($path);
        $prefix = $this->prefix($path);
        $path = substr($path, strlen($prefix));
        $parts = array_filter(explode('/', $path), 'strlen');

        foreach ($parts as $part) {
            if ('..' === $part) {
                array_pop($tokens);
            } elseif ('.' !== $part) {
                $tokens[] = $part;
            }
        }

        return $prefix . implode('/', $tokens);
    }
1034498
public final function clean_path($path) {

        $path = rtrim($path, DIRECTORY_SEPARATOR);

        $parttoremove = DIRECTORY_SEPARATOR . 'tests';

        $substr = substr($path, strlen($path) - strlen($parttoremove));
        if ($substr == $parttoremove) {
            $path = substr($path, 0, strlen($path) - strlen($parttoremove));
        }

        return rtrim($path, DIRECTORY_SEPARATOR);
    }
1200855
final public function deleteContents($folderpath, $filterByExtension = [], $filterByName = [],
                                         $filterExcludeMode = true, $recursive = true)
    {

        //1. Search $name as a folder or as a file
        if (!$this->is($folderpath)) { //if in path is a directory
            return false;
        }

        $dirh = @opendir($folderpath); //directory handler

        if ($dirh) {
            while (false !== ($file = readdir($dirh))) {
                // remove '.' and '..'
                if ($filterExcludeMode) {
                    //Excluding by name as in "file.ext"
                    if ($file == '.' || $file == '..' || in_array($file, $filterByName)) {
                        continue;
                    }
                    //Excluding extension
                    if (!empty($filterByExtension)) {
                        $fhandler = $this->getFile();
                        $extension = $fhandler->getExtension($file);
                        if (in_array($extension, $filterByExtension)) {
                            continue;
                        }
                    }
                }

                //The new path
                $newPath = $folderpath . DS . $file;
                //echo $newPath;

                //If newpath is a folder and we are deleting recursively
                if ($this->isFolder($newPath) && $recursive) {
                    $this->deleteContents($newPath, $filterByExtension, $filterByName, $filterExcludeMode, $recursive);
                }
                //Now unlink the file
                if (!static::delete($newPath)) {
                    static::setError("Could not delete {$newPath}");

                    return false;
                }
            }
            closedir($dirh);
        }

        //@TODO if long, get additional info for each path;

        return true;
    }
1180577
private function cleanEmptyArraysInPath($path)
    {
        $subs = $this->getEntries($path);
        if (!empty($subs)) {
            foreach ($subs as $subPath) {
                $this->cleanEmptyArraysInPath($subPath);
            }
        }

        if ([] === $this->get($path)) {
            $this->remove($path);
        }
    }
661496
private function deleteDirByFullPath($path, $delete_self = true, array $exclude = [])
    {
        $dir = $this->withSlash($path);

        if ($dh = opendir($dir)) {
            while ($file = readdir($dh)) {
                if (($file != '.') && ($file != '..')) {
                    $fullpath = $dir . $file;

                    if (!$delete_self && in_array($fullpath, $exclude)) {
                        continue;
                    }

                    if (is_link($fullpath)) {
                        unlink($fullpath);
                    } else {
                        if (is_dir($fullpath)) {
                            $this->deleteDirByFullPath($fullpath);
                        } else {
                            unlink($fullpath);
                        }
                    }
                }
            }

            closedir($dh);
        }

        if ($delete_self) {
            rmdir($dir);
        }
    }
630684
public function cleanDirectory($path)
    {
        $time = time();
        $maxFileAge = 3600;
        $files = (array) $this->files->files($path);
        foreach ($files as $file) {
            if ($this->files->isFile($file) === true &&
                $this->files->lastModified($file) < ($time - $maxFileAge)
            ) {
                $this->files->delete($file);
            }
        }

        return $this;
    }
760735
public function unlink($path)
    {
        $realPath = $this->resolvePath(vfsStream::path($path));
        $content  = $this->getContent($realPath);
        if (null === $content || $content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {
            return false;
        }

        if ($content->getType() !== vfsStreamContent::TYPE_FILE) {
            trigger_error('unlink(' . $path . '): Operation not permitted', E_USER_WARNING);
            return false;
        }

        return $this->doUnlink($realPath);
    }
983274
function fileDeleteLocal( $path )
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "dfs::fileDeleteLocal( '$path' )" );
        @unlink( self::cleanPath( $path ) );

        eZClusterFileHandler::cleanupEmptyDirectories( $path );
    }
968789
public static void deleteIfExists(FileSystem fs, Path path, boolean recursive) throws IOException {
    if (fs.exists(path)) {
      deletePath(fs, path, recursive);
    }
  }
656841
public function delete ($path) {
		list ($first, $rest) = self::getFirstAndRestPathElements($path);

		# If we are going still deeper...
		if (!is_null($rest)) {
			if (array_key_exists($first, $this -> data)) {
				if ($this -> data[$first] instanceof MutableTreeInterface) {
					/** @var MutableTreeInterface $tree */
					$tree = $this -> data[$first];
					$tree -> delete($rest);
				} else {
					throw new InvalidKeyException("Value at key `" . $first . "` is a scalar; cannot step further down the requested path `" . $rest . "`");
				}
			} else {
				throw new NonExistentKeyException("Key `" . $first . "` does not exist.");
			}
		} else {
			unset($this -> data[$first]);
		}

		return $this;
	}
290343
public static function delete_img($path, $isfull = false, $fsencoding = '') {
        $path = strval($path);
        if ($path == '') {
            return;
        }
        if (!$isfull) {
            $path = WEB_ROOT . $path;
        }

        $path = self::conv_to($path, $fsencoding);
        $pinfo = pathinfo($path);
        $dir = $pinfo['dirname'] . '/';
        $name = $pinfo['filename'];
        $files = [];

        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if ($file == '.' || $file == '..') {
                    continue;
                }
                if (preg_match('/^' . $name . '_?.*$/i', $file)) {
                    $files[] = $dir . $file;
                }
            }
            closedir($dh);
        }

        foreach ($files as $one) {
            self::delete($one, true);
        }
    }
14858
private function needsInitialNewline($path)
    {
        $result = false;
        if (! file_exists($path)) {
            return $result;
        }
        $fh = fopen($path, 'r');
        if ($fh === false) {
            return $result;
        }
        if (fseek($fh, -1, SEEK_END) === 0) {
            $lastChar = fgetc($fh);
            if ($lastChar !== "\n" && $lastChar !== "\r") {
                $result = true;
            }
        }
        fclose($fh);
        return $result;
    }
270393
protected function removeEmptyDirs($path)
    {
        $parentDirName = $this->getParentDirName($path);

        $res = true;
        if ($this->isDirEmpty($parentDirName)) {
            $res &= $this->rmdir($parentDirName);
            $res &= $this->removeEmptyDirs($parentDirName);
        }

        return (bool) $res;
    }
1130262
public function delete($pathToImage, $isDir = false)
    {
        $this->sizes->keys()->each(function ($size) use ($pathToImage, $isDir) {
            list($path, $name) = $this->getThumbPath($pathToImage, $size);
            $file = $path . '/' . $name;
            if ($this->storage->exists($file)) {
                if (!$isDir) {
                    $this->storage->delete($file);
                } else {
                    $this->storage->deleteDirectory($file);
                }
            }
        });
    }
488913
function _unlink($path)
    {
        $path = $this->_parse_path($path);
        if ($path === false) {
            return false;
        }

        return $this->sftp->delete($path, false);
    }