empties folder
removes all files in folder and subfolders (including any cache folders)

@throws FilesystemFolderException
193767
public function purge() {

		foreach(
			new \RecursiveIteratorIterator(
				new \RecursiveDirectoryIterator(
					$this->path,
					\FilesystemIterator::SKIP_DOTS
				),
				\RecursiveIteratorIterator::CHILD_FIRST) as $f) {

			if ($f->isDir()) {
				if(!@rmdir($f->getRealPath())) {
					throw new FilesystemFolderException(sprintf('Filesystem folder %s could not be deleted!', $f->getRealPath()));
				}

				self::unsetInstance($f->getRealPath());
			}
		    else {
		    	if(!@unlink($f->getRealPath())) {
		    		throw new FilesystemFolderException(sprintf('Filesystem file %s could not be deleted!', $f->getRealPath()));
		    	}

		    	FilesystemFile::unsetInstance($f->getRealPath());
			}
		}

	}
831006
protected function deleteCacheEntries() {

		if(($cachePath = $this->folder->getCachePath(TRUE))) {

			$di	= new \DirectoryIterator($cachePath);

			foreach($di as $fileinfo) {
				if(	$fileinfo->isDot() ||
					!$fileinfo->isFile() ||
					strpos($fileinfo->getFilename(), $this->filename) !== 0
				) {
					continue;
				}

				unlink($fileinfo->getRealPath());
			}
		}
	}
231543
private void checkEmpty(Directory dir, Path pathForException) throws FileSystemException {
    if (!dir.isEmpty()) {
      throw new DirectoryNotEmptyException(pathForException.toString());
    }
  }
275151
public function clean()
    {
        $fileSystem = new Filesystem();
        
        if ($fileSystem->exists($this->getCacheDir())) {
            $fileSystem->remove($this->getCacheDir());
        }
    }
468486
public function clean()
    {
        foreach($this->listFolder() as $f){
            if($f instanceof Folder){
                $f->delete(Folder::DELETE_FOLDER_RECURSIVE);
            } else if($f instanceof File){
                $f->delete();
            }
        }
    }
1199506
public function purgeCache($force = FALSE) {

		if(($path = $this->getCachePath($force))) {
			foreach(glob($path. '*') as $f) {
				if(!unlink($f)) {
					throw new FilesystemFolderException(sprintf('Cache folder %s could not be purged!', $this->path . self::CACHE_PATH));
				}
			}
		}

	}
979403
public function clear()
    {
        $finder = new Finder();

        /** @var \Symfony\Component\Finder\SplFileInfo $file */
        foreach ($finder->files()->in($this->cacheDir)->depth(0)->name(self::CACHE_PATH_REGEX) as $file) {
            @unlink($file->getRealPath());
        }
    }
329895
public static function emptyDirectory(string $directory): void
    {
        if (is_dir($directory)) {
            foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $path) {
                if ($path->isFile()) {
                    if (!unlink($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                } else {
                    if (!rmdir($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                }
            }
        }
    }
522411
static public void emptyDirectory(File dir) throws Exception {
		String[] fileNames = dir.list();
		if( null != fileNames ) {
			for(String fileName : fileNames){
				File file = new File(dir,fileName);
				if( file.isDirectory() ) {
					emptyDirectory(file);
				}
				boolean deleted = false;
				try {
					deleted = file.delete();
				} catch(Exception e) {
					throw new Exception("Unable to delete: "+file.getAbsolutePath(),e);
				}
				if( !deleted ){
					throw new Exception("Unable to delete: "+file.getAbsolutePath());
				}
			}
		}
	}
725504
private function clean()
    {
        foreach (Finder::find($this->namespace . '*')->from($this->tempDir)->childFirst() as $entry) {
            $path = (string)$entry;
            if ($entry->isDir()) {
                //We dont use dirs, ignore
                continue;
            }

            $updateDate = $this->cache->load($entry->getFilename());
            if ($updateDate === null) {
                @unlink($path);
            }
        }

        return;
    }
316425
private void purgeDirectories(FileSystem fs, Path root) throws IOException {
    DirectoryTraversal traversal =
        DirectoryTraversal.directoryRetriever(Arrays.asList(root), fs,
            directoryTraversalThreads, directoryTraversalShuffle);
    String prefix = root.toUri().getPath();
    
    FileStatus dir;
    while ((dir = traversal.next()) != DirectoryTraversal.FINISH_TOKEN) {
      Path dirPath = dir.getPath();
      if (dirPath.toUri().getPath().endsWith(RaidNode.HAR_SUFFIX)) {
        continue;
      }
      String dirStr = dirPath.toUri().getPath();
      if (!dirStr.startsWith(prefix)) {
        continue;
      }
      entriesProcessed.incrementAndGet();
      String src = dirStr.replaceFirst(prefix, "");
      if (src.length() == 0) continue;
      Path srcPath = new Path(src);
      if (!fs.exists(srcPath)) {
        performDelete(fs, dirPath, true);
      }
    }
  }
196340
public function clear()
	{
		// Path to cache folder
		$cacheDir = PATH_APP . DS . 'cache' . DS . '*';

		// Remove recursively
		foreach (glob($cacheDir) as $cacheFileOrDir)
		{
			$readable = str_replace(PATH_APP . DS, '', $cacheFileOrDir);
			if (is_dir($cacheFileOrDir))
			{
				if (!Filesystem::deleteDirectory($cacheFileOrDir))
				{
					$this->output->addLine('Unable to delete cache directory: ' . $readable, 'error');
				}
				else
				{
					$this->output->addLine($readable . ' deleted', 'success');
				}
			}
			else
			{
				// Don't delete index.html
				if ($cacheFileOrDir != PATH_APP . DS . 'cache' . DS . 'index.html')
				{
					if (!Filesystem::delete($cacheFileOrDir))
					{
						$this->output->addLine('Unable to delete cache file: ' . $readable, 'error');
					}
					else
					{
						$this->output->addLine($readable . ' deleted', 'success');
					}
				}
			}
		}

		$this->output->addLine('Clear cache complete', 'success');
	}
719177
private void cleanupDirectories() throws IOException {
		ShutdownHookUtil.removeShutdownHook(shutDownHook, getClass().getSimpleName(), LOG);

		final String webTmpDir = configuration.getString(WebOptions.TMP_DIR);

		FileUtils.deleteDirectory(new File(webTmpDir));
	}
592042
protected function cleanup()
    {
        // if $this->fs is an object, the Filesystem has been used, clean it up.
        if (is_object($this->fs)) {
            if ($this->fs->isDirectory($this->tempPath)) {
                $this->fs->deleteDirectory($this->tempPath, false);
            }
        }
    }
262966
public function clear()
    {
        $files=@scandir($this->getCacheDir());
        foreach ($files as $file){
            if($file != "." && $file != ".."){
                $file=$this->getCacheDir().$file;
                @unlink($file);
            }
        }
    }
1159900
public static void deleteDirectories(FileSystem fs, List<String> directoriesToDelete, boolean recursive, boolean moveToTrash) throws IOException {
    for (String directory : directoriesToDelete) {
      if (moveToTrash) {
        moveToTrash(fs, new Path(directory));
      } else {
        deletePath(fs, new Path(directory), recursive);
      }
    }
  }
328618
public void clean() {
        final Path bPath = FileSystems.getDefault().getPath(basePath);
        for (int i = 0; i < 3; i++) {
            try {
                final CleanUpFileVisitor visitor = new CleanUpFileVisitor();
                Files.walkFileTree(bPath, visitor);
                if (!visitor.hasErrors()) {
                    print("Deleted " + basePath);
                    return;
                } else if (useLogger && logger.isDebugEnabled()) {
                    for (final Throwable t : visitor.getErrors()) {
                        logger.debug("Could not delete files/directories.", t);
                    }
                }
            } catch (final Exception e) {
                print(e.getMessage() + " Retring to delete it.");
                try {
                    Thread.sleep(1000);
                } catch (final InterruptedException ignore) {
                    // ignore
                }
            }
        }
        print("Failed to delete " + basePath + " in this process.");
    }