Remove the contents of a directory, but not the directory itself.

@param string $dir
@param bool $preserveGit
@return bool
426337
public function clean($dir, $preserveGit = false)
    {
        $filesystem = new Filesystem();

        if ( ! $filesystem->exists($dir)) {
            return $filesystem->makeDirectory($dir, 0755, true);
        }

        foreach (new FilesystemIterator($dir) as $file) {
            if ($preserveGit && $file->getFilename() == '.git') {
                continue;
            }
            if ($file->isDir() && ! $file->isLink()) {
                $filesystem->deleteDirectory($file);
            } else {
                $filesystem->delete($file);
            }
        }

        return true;
    }
35080
private function removeTemporaryDirectory($dir, $rmBaseDir = false)
    {
        $itemsToIgnore = array('.', '..', '.htaccess');

        $files = array_diff(scandir($dir), $itemsToIgnore);
        foreach ($files as $file) {
            if (is_dir("$dir/$file")) {
                $this->removeTemporaryDirectory(
                    "$dir/$file",
                    $file == 'smarty' ? $rmBaseDir : true
                );
            } else {
                @unlink("$dir/$file");
            }
        }
        if ($rmBaseDir) {
            @rmdir($dir);
        }
    }
634814
public function delTree($dir)
    {
        if (! file_exists($dir)) {
            return false;
        }

        $files = array_diff(scandir($dir), ['.', '..']);

        $this->deleteAllFiles($dir, $files);

        return rmdir($dir);
    }
874133
public function isDir($dir)
	{
		$current = $this->pwd();
		try {
			$this->chdir($dir);
		} catch (FtpException $e) {
		}
		$this->chdir($current);
		return empty($e);
	}
551184
private function recursiveUnlink($dir)
    {
        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($iterator as $file) {
            if ($file->isDir()) {
                rmdir($file);
            } else {
                unlink($file);
            }
        }

        rmdir($dir);
    }
802889
public function dirDelete($dir)
    {
        $dir = $this->alias->resolve($dir);

        if (!is_dir($dir)) {
            return;
        }

        $this->_dirDelete($dir);
    }
1220044
public static function deleteFiles($dir) {
		$dir = self::normalizePath($dir);
		if (\is_dir($dir)) {
			$files = \scandir($dir);
			foreach ($files as $file) {
				$fullPath = self::normalizePath(self::combinePath($dir, $file));
				if ($file != "." && $file != "..") {
					if (\is_dir($fullPath))
						self::deleteFiles($fullPath);
					else
						@\unlink($fullPath);
				}
			}
			@\rmdir($dir);
		}
		return true;
    }
1091994
protected static function deleteDir($directory) {
		if(substr($directory,-1) == '/')
			$directory = substr($directory, 0, -1);
		if(!file_exists($directory) || !is_dir($directory))
			return false;
		elseif(is_readable($directory)) {
			$handle = opendir($directory);
			while(false !== ($item = readdir($handle))) {
				if($item != '.' && $item != '..') {
					$path = $directory.'/'.$item;
					if(is_dir($path))
						static::deleteDir($path);
					else
						unlink($path);
				}
			}
			closedir($handle);
			if(!rmdir($directory))
				return false;
		}
		return true;
	}
1200202
public static function removeDirectory($dir = '')
    {
        if ($dir == '' || $dir == NULL || $dir == '/')
            return false;

        $files = array_diff(scandir($dir), array('.','..')); 
        foreach ($files as $file)
            (is_dir("$dir/$file")) ? CiiFileDeleter::removeDirectory("$dir/$file") : unlink("$dir/$file"); 

        return rmdir($dir); 
    }
405265
protected static function cleanDir($dir) {
		
		if (isset($dir[0])) {
			$dir = trim($dir);
			$dir = ($dir[0] == DIRECTORY_SEPARATOR) ? ltrim($dir, DIRECTORY_SEPARATOR) : $dir;
			$dir = ($dir[strlen($dir)-1] == DIRECTORY_SEPARATOR) ? rtrim($dir, DIRECTORY_SEPARATOR) : $dir;
		}
		
		return $dir;
		
	}
409955
public function clearDirectory($dir)
    {
        if (empty($dir) || !@is_dir($dir)) {
            return false;
        }

        $iterator = new \RecursiveDirectoryIterator($dir);
        $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current) {
            /** @var \SplFileInfo $current */
            $filename = $current->getBasename();
            // Check for files and dirs starting with "dot" (.gitignore, etc)
            return !($filename && $filename[0] === '.');
        });

        /** @var \SplFileInfo[] $listing */
        $listing = new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($listing as $item) {
            $path = $item->getPathname();
            $item->isDir() ? rmdir($path) : unlink($path);
        }
        return true;
    }
582924
protected function rmdir($dir) {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($iterator as $file) {
            $name = $file->getPathname();

            if (substr($name, -1) === '.') {
                continue;
            }

            if ($file->isDir()) {
                // Remove dir
                rmdir($name);
            } else {
                // Remove file
                unlink($name);
            }
        }

        // Remove the directory itself
        rmdir($dir);
    }
711503
public function chdir($dir)
    {
        return ($this->isConnected() === true) ? ftp_chdir($this->getConnection(), $dir) : false;
    }
1188965
public static function directory_contents($dir)
    {
        $contents = array();
        foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS)) as $pathname => $fi) {
            $contents[] = $pathname;
        }
        natsort($contents);
        return $contents;
    }
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;
    }
701174
public function cd($dir = null)
    {
        $dir = $this->_getAbsoluteRemotePath($dir);
        if (false === is_dir($dir)) {
            return $this->_trigger_error(sprintf('Unable to change remote directory to %s.', $dir));
        }
        $this->_remotepath = $dir;

        return true;
    }
661303
protected function emptyDirectory($directory)
    {
        foreach ($this->doListContents($directory, true) as $path) {
            $this->deletePath($path);
        }
    }