Checks to see if file exists

@param null $directory
@return bool
979108
public function fileExists($directory = null)
    {
        $directory = ($directory) ?: $this->fileDirectory;
        $fileExists = file_exists($this->publicDirectory . $directory . $this->file);
        return $fileExists;
    }
42369
public function getFiles($directory)
    {
        $path = $this->base_path."/{$directory}";

        if (!is_dir($path)) {

            return file_exists($path) ? collect([$path]) : collect();
        }

        try { 
            return collect(File::allFiles($path));
        } catch (\Exception $e) {
            return collect();
        }
    }
1014034
public static function RecursiveRemoveDir($directory, $empty = false)
    {
        // if the path has a slash at the end we remove it here
        if(substr($directory, -1) == '/')
        {
            $directory = substr($directory, 0, -1);
        }

        // if the path is not valid or is not a directory ...
        if(!file_exists($directory) || !is_dir($directory))
        {
            return false;

            // ... if the path is not readable
        }
        elseif(!is_readable($directory))
        {
            return false;
        }
        else
        {
            $handle = opendir($directory);

            while(false !== ($item = readdir($handle)))
            {
                if($item != '.' && $item != '..')
                {
                    // we build the new path to delete
                    $path = $directory . '/' . $item;

                    // if the new path is a directory
                    if(is_dir($path))
                    {
                        self::RecursiveRemoveDir($path);

                        // if the new path is a file
                    }
                    else
                    {
                        if(!unlink($path))
                        {
                            return false;
                        }
                    }
                }
            }

            closedir($handle);

            if($empty == false)
            {
                if(!rmdir($directory))
                {
                    return false;
                }
            }

            return true;
        }
    }
648784
public static function isLink(string $dir = ''): bool
    {
        $dir = static::normalizePath($dir);
        return static::exists($dir) && \is_link($dir);
    }
35070
public function rmdir($directory = null)
    {
        if (\ftp_rmdir($this->_stream, $directory)) {
            return true;
        }

        $this->error = 'Failed to remove directory "'.$directory.'"';

        return false;
    }
454650
public function isIn($directory, $cwd = null)
	{
		$dir = Path::info($directory);
		if ($dir->isEmpty()) {
			throw new \InvalidArgumentException('Directory is empty.');
		}
		$dir = $dir->normalize()->assumeDirectory();
		$self = $this->normalize();
		
		if (! $dir->isAbsolute() && is_null($cwd)) {
			throw new \InvalidArgumentException(sprintf('Directory "%s" is not absolute, you have to provide a working directory.', $directory));
		}
		if (! $self->isAbsolute() && is_null($cwd)) {
			throw new \InvalidArgumentException(sprintf('Path "%s" is not absolute, you have to provide a working directory.', $this));
		}
		if (! is_null($cwd)) {
			$cwd = Path::info($cwd)->normalize()->assumeDirectory();
			if (! $cwd->isAbsolute()) {
				throw new \InvalidArgumentException(sprintf('Working directory "%s" must be absolute.', $cwd));
			}
			if ($cwd->isEmpty()) {
				throw new \InvalidArgumentException('Working directory is empty.');
			}
			$dir = $dir->abs($cwd);
			$self = $self->abs($cwd);
		}
		
		if (strpos($self->__toString(), $dir->__toString()) === 0) {
			return true;
		}
		return false;
	}
492641
public static boolean exists(@NonNull String name, @NonNull File directory) {
        if (name == null) { throw new IllegalArgumentException("name cannot be null."); }
        if (directory == null) { throw new IllegalArgumentException("directory cannot be null."); }
        return getDatabasePath(directory, name).exists();
    }
396969
public function hasSupport($dir = null)
    {
        try {
            list ($output) = $this->getSystemService()->execute('bin/phpunit --version', $dir);

            if (0 < preg_match('/^PHPUnit\s+[0-9]+\.[0-9]+\.[0-9]+/', $output)) {
                return true;
            }
            return false;
        } catch (\Exception $e) {
            return false;
        }
    }
44714
public static function addDirectory($directory = '.')
    {
        $directory = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $directory);
        $directory = rtrim($directory, '/\\');
        $directory = empty($directory) ? '.' : $directory;
        array_push(self::$configDirectory, $directory);
        return true;
    }
876085
private function _delete($filename, $directory = null)
    {
        $cache_path = $this->config->get('cache_path');

        if (is_null($directory)) {
            $path = $cache_path.$this->config->get('object_dir').$filename.'.cache';
        } else {
            $path = $cache_path.$directory.$filename.'.cache';
        }

        // nope. not here.
        if ( ! file_exists($path)) return true;
        return (bool) unlink($path);
    }
57290
protected function purgeDir($directory)
	{
		if( ! $this->filesystem->isDirectory($directory))
			return true;

		if($this->filesystem->isWritable($directory))
			return $this->filesystem->cleanDirectory($directory);

		$this->error($directory . ' is not writable');

		return false;
	}
1026588
protected function dirExists($dir)
    {
        if ($this->files->exists($dir)) {

            if ( ! $this->files->isDirectory($dir)) {
                throw new RuntimeException("The given directory [$dir] is not a directory.");
            }

            return true;
        }

        return false;
    }
1331153
protected function isDrupalRoot($directory) {
    if (!empty($directory) && is_dir($directory) && file_exists($directory . DIRECTORY_SEPARATOR . '/index.php')) {
      // Drupal 7 root.
      // We check for the presence of 'modules/field/field.module' to differentiate this from a D6 site
      return (file_exists($directory . DIRECTORY_SEPARATOR . 'includes/common.inc')
        && file_exists($directory . DIRECTORY_SEPARATOR . 'misc/drupal.js')
        && file_exists($directory . DIRECTORY_SEPARATOR . 'modules/field/field.module'));
    }
    return FALSE;
  }
384062
public function dirExists($dir)
    {
        return ($this->isConnected() === true) ? ftp_rmdir($this->connectionString.$dir) : false;
    }
383835
public function ensureDirectory($directory)
	{
		if(!is_dir($directory))
		{
			$this->ensureDirectory(dirname($directory));
			echo "      mkdir ".strtr($directory,'\\','/')."\n";
			mkdir($directory);
		}
	}
442366
public function createDirectory($directory)
    {
        // create parent directory if needed
        $parent = dirname($directory);
        if (!$this->directoryExists($parent)) {
            $this->createDirectory($parent);
        }

        if (ftp_mkdir($this->connection(), $directory) === false) {
            throw new \RuntimeException(sprintf(
                'Could not create directory \'%s\'.',
                $directory
            ));
        }

        return true;
    }
163741
public function ls($dir = null)
    {
        $dir = $this->_getAbsoluteRemotePath(null === $dir ? $this->_remotepath : $dir);
        if (false === $ls = @scandir($dir)) {
            return $this->_trigger_error(sprintf('Unable to list files of remote directory %s.', $dir));
        }

        return $ls;
    }