Find a list of GEDCOM files in a folder

@param string $folder

@return array
972691
private function gedcomFiles(string $folder): array
    {
        $d     = opendir($folder);
        $files = [];
        while (($f = readdir($d)) !== false) {
            if (!is_dir(WT_DATA_DIR . $f) && is_readable(WT_DATA_DIR . $f)) {
                $fp     = fopen(WT_DATA_DIR . $f, 'rb');
                $header = fread($fp, 64);
                fclose($fp);
                if (preg_match('/^(' . Gedcom::UTF8_BOM . ')?0 *HEAD/', $header)) {
                    $files[] = $f;
                }
            }
        }
        sort($files);

        return $files;
    }
1187513
public static function delFolder($bucket, $folder) {
        if (empty($bucket) || empty($folder)) {
            return array(
                    'code' => COSAPI_PARAMS_ERROR,
                    'message' => 'bucket or path is empty');
        }

        $folder = self::normalizerPath($folder, True);

        return self::delBase($bucket, $folder);
    }
1261375
public static List<String> getFilesInFolder(String folder, String ext) {
		// tryto find using normal file system lookup
		List<String> files = new Vector<>();
		File dir = new File(folder);
		if (dir.exists() && dir.isDirectory()) {
			String[] list = dir.list();
			for (String file : list) {
				if (file.endsWith(ext)) {
					files.add(file);
				}
			}
		}
		return files;
	}
1372145
public static function getLangs($folder = '')
    {
        $langs = [];

        $iterator = new \DirectoryIterator(ForumEnv::get('FORUM_ROOT').'lang/');
        foreach ($iterator as $child) {
            if (!$child->isDot() && $child->isDir() &&
                file_exists($child->getPathname().DIRECTORY_SEPARATOR.'install.po')) {
                // If the lang pack is well formed, add it to the list
                $langs[] = $child->getFileName();
            }
        }

        natcasesort($langs);
        return $langs;
    }
1243926
protected function getFileList($dir)
	{
		$finder = new Finder();
		$iterator = $finder
			->ignoreDotFiles(false)
			->files()
			->sortByName()
			->in($dir)
		;

		$files = array();
		foreach ($iterator as $file)
		{
			/** @var \SplFileInfo $file */
			$files[] = str_replace(DIRECTORY_SEPARATOR, '/', substr($file->getPathname(), strlen($dir) + 1));
		}

		return $files;
	}
1047143
public static function getFolders($root)
    {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::SELF_FIRST,
            RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
        );

        $paths = [
            $root,
        ];

        foreach ($iterator as $path => $dir) {
            if (true === $dir->isDir()) {
                $paths[] = $path;
            }
        }

        return $paths;
    }
1239080
private static function getFiles(string $projectRootDirectory): array
    {
        $files   = self::getDocsFiles($projectRootDirectory);
        $files[] = self::getMainReadme($projectRootDirectory);

        return $files;
    }
1298510
public static function GetFirstExisting( string $folder ) : string
   {

      // Remove directory separator from $folder end
      $folder = \rtrim( $folder, '\\/' );

      if ( \Niirrty\strContains( $folder, '/' ) && \Niirrty\strContains( $folder, '\\' ) )
      {
         // Uses mixed directory separators, normalize it
         if ( \DIRECTORY_SEPARATOR == '\\' )
         {
            $folder = \str_replace( '/', '\\', $folder );
         }
         else
         {
            $folder = \str_replace( '\\', '/', $folder );
         }
      }

      // Get the current sub folder level
      $level =
         \count(
            \explode(
               \DIRECTORY_SEPARATOR,
               \ltrim( $folder, '\\/' )
            )
         );

      for ( $i = 0; $i < $level && ! \is_dir( $folder ); ++$i )
      {
          $f = \dirname( $folder );
          if ( empty( $f ) || $f == $folder )
          {
             return '/';
          }
          $folder = $f;
      }

      \clearstatcache();

      return $folder;

   }
91554
public function resolve(ExtendedFolderInterface $folder)
    {
        $metaSets = [];
        foreach ($folder->getMetasets() as $metaSetId) {
            $metaSet = $this->metaSetManager->find($metaSetId);
            if ($metaSet) {
                $metaSets[] = $metaSet;
            }
        }

        return $metaSets;
    }
729273
public static function rmdir($folder)
    {
        set_time_limit(0);

        if(!file_exists($folder)){
            return false;
        }

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

        foreach ($files as $file) {
            $file = $folder . DIRECTORY_SEPARATOR . $file;
            (is_dir($file) && !is_link($folder)) ? self::rmdir($file) : unlink($file);
        }

        return rmdir($folder);
    }
134574
public function show($folder)
    {
        $this->manager->resetPath($folder);

        if (!$this->manager->blobExists()) {
            return $this->json('File not found.', 404);
        }

        $list = $this->manager->folderContent();

        return $this->json($list);
    }
766022
public function getFilesList($dir)
	{
		$list = [];
		$iterator = Aws\recursive_dir_iterator($dir);
		foreach ($iterator as $filename) {
			$list[] = $filename;
		}
		return $list;
	}
764998
public function getFileList($order = 'desc')
    {
        if (! is_null($this->itemsOrderCache) && isset($this->itemsOrderCache[$order])) {
            return $this->itemsOrderCache[$order];
        }

        // Order Files by date newer to older
        $this->items->sort(function ($a, $b) use ($order) {
            if ($a == $b) {
                return 0;
            }
            if ($order === 'asc') {
                return ($a < $b) ? -1 : 1;
            }

            return ($a > $b) ? -1 : 1;
        });

        $this->itemsOrderCache[$order] = $this->items->all();

        return $this->itemsOrderCache[$order];
    }
435221
public function files($dir)
    {
        $dir = $this->alias->resolve($dir);

        $files = [];
        foreach ($this->glob($dir . (strpos($dir, '*') === false ? '/*' : ''), SCANDIR_SORT_ASCENDING) as $item) {
            if (is_file($item)) {
                $files[] = $item;
            }
        }

        return $files;
    }
1327016
public function listFiles($directory)
    {
        $writeBinn= new BinnList;

        $writeBinn->addUint8(self::FSERV_READDIR);
        $writeBinn->addStr($directory);     // Dir path
        $writeBinn->addUint8(0);       // Mode

        $read = $this->writeAndReadSocket($writeBinn->serialize());

        $readBinn = new BinnList;

        $readBinn->binnOpen($read);
        $results = $readBinn->unserialize();

        if ($results[0] != self::FSERV_STATUS_OK) {
            // Error
            throw new RuntimeException('GDaemon List files error:' . isset($results[1]) ? $results[1] : 'Unknown');
        }

        $filesList = $results[2];
        $returnList = [];

        foreach($filesList as &$file) {

            if (in_array(basename($file[0]), ['.', '..'])) {
                continue;
            }

            $returnList[] = basename($file[0]);
        }

        return $returnList;
    }
490892
private function _list(string $path): array {
        $result = [];
        $scan = glob($path . '/*');
        foreach ($scan as $item) {
            if (is_dir($item)) {
                $result[basename($item)] = $this->_list($item);
            } else {
                $result[] = basename($item);
            }
        }
        return $result;
    }
1177840
function getFiles($folder, $name)
    {
        $filesArray = array();
        $files = Folder::files($folder, null, false, true);

	    $path = JFusionFramework::getPluginPath($name);

        foreach ($files as $file) {
            $file = str_replace($path . '/', '', $file);
	        $file = str_replace($path . '\\', '', $file);
            $data = file_get_contents($file);
            $filesArray[] = array('name' => $file, 'data' => $data);
        }
        $folders = Folder::folders($folder, null, false, true);
        if (!empty($folders)) {
            foreach ($folders as $f) {
                $filesArray = array_merge($filesArray, $this->getFiles($f, $name));
            }
        }
        return $filesArray;
    }