php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31674 glob() returns no results for dirs with brackets in them.
Submitted: 2005-01-24 03:31 UTC Modified: 2005-01-24 11:01 UTC
From: miika dot ahonen at mbnet dot fi Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.0.3 OS: Linux
Private report: No CVE-ID: None
 [2005-01-24 03:31 UTC] miika dot ahonen at mbnet dot fi
Description:
------------
In an attempt to glob() directory with bracket ('[' and/or ']') in its name, I get no results at all.

Reproduce code:
---------------
$dir = "./dir[with]brackets";

if (!is_dir($dir))
   mkdir($dir);

for ($i = 0; $i < 3; $i++)
   file_put_contents($dir."/file.".$i, "foo".$i."\n");

var_dump( glob($dir."/*") );

Expected result:
----------------
Array containing files in the said directory.

Actual result:
--------------
Empty array.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-24 08:10 UTC] derick@php.net
Brackets make a character class,just as in regular expressions. Escape them with a \.
 [2005-01-24 11:01 UTC] miika dot ahonen at mbnet dot fi
I don't think that explains why first doing chdir() to such directory and doing just glob("*") fails in similar manner. The chdir() works fine in such cases and with readdir() I can get everything I want from there without any problems.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC