Is Directory Empty?

@param string $path Path.
@return bool True/false.
963760
public static function empty_dir(string $path) {
		if (! @\is_readable($path) || ! @\is_dir($path)) {
			return false;
		}

		// Scan all files in dir.
		if ($handle = @\opendir($path)) {
			while (false !== ($file = @\readdir($handle))) {
				// Anything but a dot === not empty.
				if (('.' !== $file) && ('..' !== $file)) {
					return false;
				}
			}
			\closedir($handle);
			return true;
		}

		return false;
	}
327152
private static function checkSavePath($path) {
            if (is_string($path)) {
                $dir = dirname($path);

                return file_exists($dir) && is_writeable($dir);
            } elseif (is_resource($path)) {
                return true;
            }

            return false;
        }
646825
public static final function ppath ($path){
		while (!is_dir($path) && strlen($path) > 0){
			$path = preg_replace('/[^\/]+\/?$/', null, $path);
		}

		return !empty($path) ? $path : false;
	}
197501
protected function validatePath($path)
    {
        if (empty($path)) {
            return false;
        }

        // we are always operating from root directory
        // so forbid relative paths
        if (false !== strpos($path, '..')) {
            return false;
        }

        return true;
    }
542944
protected function _subdirs($path) {
		$stat = $this->_stat($path);
		
		if ($stat['mime'] == 'directory') {
		 $files = $this->_scandir($path);
		 foreach ($files as $file) {
			$fstat = $this->_stat($file);
			if ($fstat['mime'] == 'directory') {
				return true;
			}
		 }
		
		}
		
		return false;
	}
1275619
private function createPathIfNeeded(string $path) : bool
    {
        if (! is_dir($path)) {
            if (@mkdir($path, 0777 & (~$this->umask), true) === false && ! is_dir($path)) {
                return false;
            }
        }

        return true;
    }
89666
public function has($path)
    {
        $location = $this->applyPathPrefix($path);

        if ($this->s3Client->doesObjectExist($this->bucket, $location, $this->options)) {
            return true;
        }

        return $this->doesDirectoryExist($location);
    }
609107
public function hasDir($path)
    {
        $meta = $this->getMetadata($path);
        return ($meta && isset($meta['hasdir'])) ? $meta : [
            'hasdir' => true
        ];
    }
369184
protected function checkPath($path)
    {
        foreach ($this->chroots as $chroot) {
            if (StringHelper::contains($path, $chroot)) {
                return true;
            }
        }
        return false;
    }
317728
private function checkPath($path)
    {
        return file_exists($path) && is_readable($path) && ($resources = scandir($path)) && (count($resources) > 2);
    }
813533
public function obfuscateDirectory(string $path) : bool
    {
        $this->plain_path = rtrim($path, "/");
        if (is_dir($this->plain_path) === false) {
            $this->addErrorMessage("The specified directory does not exist");
            return false;
        }

        if (is_readable($this->plain_path) == false) {
            $this->addErrorMessage("No permissions to read directory");
            return false;
        }

        if ($this->isObfuscatedDirectory($this->plain_path) == true) {
            $this->addRuntimeMessage("The specified directory is already obfuscated");
            return false;
        }

        return true;
    }
255019
public function folderExists($path)
    {
        $folderName = basename($path);
        $folderPath = dirname($path);

        $path = self::validatePath($folderPath);
        $fullPath = $this->getMediaPath($path);

        $folders = $this->getStorageDisk()->directories($fullPath);
        foreach ($folders as $folder) {
            if (basename($folder) == $folderName) {
                return true;
            }
        }

        return false;
    }
168614
public static function isDirectory(string $path) : bool
    {
        try {
            return ErrorCatcher::run(static function() use ($path) {
                return is_dir($path);
            });
        } catch (\ErrorException $e) {
            throw new IoException('Error checking if ' . $path . ' is a directory', 0, $e);
        }
    }
1318455
public function has($path)
    {
        try {
            $this->api->resource($path);
        } catch (Exception $e) {
            return false;
        }

        return true;
    }
874133
public function isDir($dir)
	{
		$current = $this->pwd();
		try {
			$this->chdir($dir);
		} catch (FtpException $e) {
		}
		$this->chdir($current);
		return empty($e);
	}
232015
public static function delete($path)
    {
        if (is_dir($path)) {
            Folder::delete($path);
        } elseif (is_file($path)) {
            File::delete($path);
        }

        return true;
    }
1151546
public function has($path)
    {
        $x = $this->xpath($path);

        return count($x) ? true : false;
    }