Deletes all files in directory.

@internal for internal use only

@param String $dir
1032
public static function deleteAllFilesInDirectory ($dir) {
        $dirIterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
        foreach (new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            $file->isDir() ? rmdir($file) : unlink($file);
        }
    }
1042112
protected function clearCacheDirectory($directory)
    {
        foreach ($this->filesToClear($directory) as $file) {
            if ($file->isDir()) {
                $this->filesystem->deleteDirectory($file->getPathname());
            } else {
                $this->filesystem->delete($file->getPathname());
            }
        }
    }
888073
public static function deleteDir($dir)
    {
        $d = dir($dir);
        while (false !== ($entry = $d->read())) {
            if ($entry == '.' || $entry == '..') {
                continue;
            }

            $currele = $d->path . '/' . $entry;
            if (is_dir($currele)) {
                if (self::isEmpty($currele)) {
                    rmdir($currele);
                } else {
                    self::deleteDir($currele);
                }
            } else {
                unlink($currele);
            }
        }
        $d->close();

        rmdir($dir);
        return true;
    }
393401
public static function emptyContents($dir) {
        $iterator = new \FilesystemIterator($dir, \FilesystemIterator::SKIP_DOTS);
        if (!$iterator->valid()) {
            return;
        }
        foreach($iterator as $fileinfo) {
            if ($fileinfo->isDir()) {
                self::deleteFolder($fileinfo->getPathname());
            }
            else {
                unlink($fileinfo->getPathname());
            }
        }
    }
1000607
public function clear($dir = '') 
    {
        $path = $this->getCachePath($dir . '/tmp');
        $dir  = dirname($path);
        
        if(is_dir($dir)) {
            static::clearDir($dir, false);
        }
        
        $this->temp = [];
        $this->stats['execTimes'] ++;
    }
296806
protected function deleteDirectory($dir)
    {
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $fileInfo) {
            $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');

            $todo($fileInfo->getRealPath());
        }

        rmdir($dir);
    }
1344571
protected function deleteFromDir(
        /*# string */ $dir,
        /*# int */ $maxlife = 0,
        /*# bool */ $removeDir = false
    )/*# : bool */ {
        $now = time();
        if (is_dir($dir)) {
            $files = scandir($dir);
            foreach ($files as $file) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                $sub = $dir . DIRECTORY_SEPARATOR . $file;
                $res = true;
                if (is_dir($sub)) {
                    $res = $this->deleteFromDir($sub, $maxlife, true);
                } else {
                    if (!$maxlife || $now - filemtime($sub) > $maxlife) {
                        $res = unlink($sub);
                    }
                }
                if ($res === false) {
                    return $this->falseAndSetError(
                        Message::get(Message::CACHE_FAIL_DELETE, $sub),
                        Message::CACHE_FAIL_DELETE
                    );
                }
            }
            if ($removeDir && ! @rmdir($dir)) {
                return $this->falseAndSetError(
                    Message::get(Message::CACHE_FAIL_DELETE, $dir),
                    Message::CACHE_FAIL_DELETE
                );
            }
        }
        return true;
    }
415573
public static void deleteRecursive(@Nonnull File dir) throws IOException {
        deleteRecursive(fileToPath(dir), PathRemover.PathChecker.ALLOW_ALL);
    }
682109
public static function removeDir(string $dir)
    {
        foreach (scandir($dir) as $file) {
            if ('.' === $file || '..' === $file) {
                continue;
            }
            if (is_dir($dir . '/' . $file)) {
                self::removeDir($dir . '/' . $file);
            } else {
                unlink($dir . '/' . $file);
            }
        }
        rmdir($dir);
    }
853565
public static function clear_directory($directory)
    {
        foreach (scandir($directory) as $file) {
            if ($file !== '.' and $file !== '..') {
                unlink($directory.$file);
            }
        }
    }
782291
public function deleteFiles($folder, $rmdir = false)
    {
        array_map('unlink', glob($folder . DS . '*'));
        if ($rmdir) {
            rmdir($folder);
        }
    }
1293813
private function deleteFiles(Directory $path)
    {
        foreach ($this->manager->findFiles($path) as $file) {
            $this->wrapper->delete($file->getRealpath());
        }
    }
544179
protected function flushDir($dir)
    {
        if (!file_exists($dir)) {
            echo "HELP cant find ".$dir."\n";
            return;
        }
        $objects = scandir($dir);
        foreach ($objects as $object) {
            try {
                $this->deleteFile($object, $dir);
            } catch (Exception $e) {
                echo "Can't remove Folder/File ".$dir.DIRECTORY_SEPARATOR.$object."<br />\n"
                        . $e->getMessage()."<br />\n";
            }
        }
    }
110060
public static function deleteFolder($dir) {

		if (!file_exists($dir)) return true;

		if (!is_dir($dir) or is_link($dir)) return unlink($dir);

		foreach (scandir($dir) as $item) {

			if ($item == '.' or $item == '..') continue;

			if (!self::deleteFolder($dir . "/" . $item)) {
				chmod($dir . "/" . $item, 0777);
				if (!self::deleteFolder($dir . "/" . $item)) return false;
			}

		}

		return rmdir($dir);

	}
1276093
public static void deleteChilsDirsIfEmpty(File dir){
		File childs[]=getChildDirs(dir);
		
		for (File file:childs){
			deleteChilsDirsIfEmpty(file);
			if (!file.delete()) {
				log.info("No se ha podido borrar el directorio " + file.getAbsolutePath());
			}
		}
		
	}
644272
public function delDir($dir)
    {
        $dir = $this->checkpath($dir);
        if (@!ftp_rmdir($this->linkid, $dir)) {
            $this->close();
            return false;
        }
        $this->close();
        return true;
    }
714507
protected function rotate($dir)
    {
        $files = Folder::files($dir);

        rsort($files);

        array_splice($files, 0, 20);

        return File::delete($files);
    }