@trigger_error('file_scan_directory() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\File\FileSystemInterface::scanDirectory() instead. See https://www.drupal.org/node/3038437',E_USER_DEPRECATED);
$files=[];
// Avoid warnings when opendir does not have the permissions to open a
// directory.
try{
if(is_dir($dir)){
if($handle=@opendir($dir)){
while(FALSE!==($filename=readdir($handle))){
// Skip this file if it matches the nomask or starts with a dot.