In this post I am going to explain how to check file exists in directory using isExists method in magento 2.

Use below code snippet to check file is exists or not.

private $_fileDriver;
    
public function __construct(
	\Magento\Backend\Block\Template\Context $context,
	\Magento\Framework\Filesystem\Driver\File $fileDriver,
	array $data = []
)
{        
	$this->_fileDriver = $fileDriver;
	parent::__construct($context, $data);
}

public function getFileExists()
{
	$file = '/home/user/public_html/pub/media/logo/default/logo.png';
	
	if ($this->_fileDriver->isExists($file)) {
		return "Yes";
	} else {
		return "No";
	}
}

Thats it. Enjoy Magento 2!!