NFePHP\Common\Files\FilesFolders::listDir PHP Метод

listDir() публичный статический Метод

listDir Obtem todo o conteúdo de um diretorio, e que atendam ao critério indicado.
public static listDir ( $folder, string $fileMatch = '*-nfe.xml', boolean $retpath = false ) : array
$fileMatch string Critério de seleção pode ser usados coringas como *-nfe.xml
$retpath boolean se true retorna o path completo dos arquivos se false so retorna o nome dos arquivos
Результат array com os nome dos arquivos que atendem ao critério estabelecido ou false
    public static function listDir($folder, $fileMatch = '*-nfe.xml', $retpath = false)
    {
        if ($folder == '' || $fileMatch == '') {
            throw new Exception\InvalidArgumentException("É necessário passar os parametros diretório e filtro!!!");
        }
        if (!is_dir($folder)) {
            throw new Exception\InvalidArgumentException("O diretório não existe {$folder} !!!");
        }
        $aList = array();
        $search = $folder;
        if (substr($folder, -1) == DIRECTORY_SEPARATOR) {
            $search = substr($folder, 0, strlen($folder) - 1);
        }
        $searchmatch = $search . DIRECTORY_SEPARATOR . $fileMatch;
        $aGlob = glob($searchmatch);
        $aList = $aGlob;
        if (!$retpath && !empty($aGlob)) {
            $aList = array();
            foreach ($aGlob as $pathFile) {
                $aList[] = str_replace($search . DIRECTORY_SEPARATOR, '', $pathFile);
            }
        }
        return $aList;
    }

Usage Example

 /**
  * @expectedException NFePHP\Common\Exception\InvalidArgumentException
  * @expectedExceptionMessage O diretório não existe /qualquercoisa !!!
  */
 public function testListDirFail()
 {
     $aList = array();
     $folderBase = '/qualquercoisa';
     $files = FilesFolders::listDir($folderBase, '*.*', false);
     $this->assertEquals($aList, $files);
 }
All Usage Examples Of NFePHP\Common\Files\FilesFolders::listDir