|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
19 - 17 = ?
Subscribe to this entry?

 [2005-01-24 03:31 UTC] miika dot ahonen at mbnet dot fi
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))

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-24 08:10 UTC]
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: Fri May 24 06:01:38 2024 UTC