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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: miika dot ahonen at mbnet dot fi
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 04:05:45 2022 UTC