Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7919331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:49:49+00:00 2026-06-03T15:49:49+00:00

On a Windows machine, the following script: <?php mkdir(c:\\[test]); file_put_contents(c:\\[test]\\test.txt, some content); chdir(c:\\[test]); echo

  • 0

On a Windows machine, the following script:

<?php

mkdir("c:\\[test]");
file_put_contents("c:\\[test]\\test.txt", "some content");
chdir("c:\\[test]");
echo getcwd()."\n";
var_dump(glob('*'));

?>

Displays this:

C:\[test]
array(0) {
}

When this is expected:

C:\[test]
array(1) {
    [0]=>
    string(8) "test.txt"
}

I understand that glob treats brackets as special characters, when found in the pattern parameter.

The pattern * matches any file in the current working directory. However, glob()
behaves as though it was run with the pattern c:\\[test]\\*

The brackets are then being interpreted as part of the pattern, when in fact they
are part of the directory.

Is glob supposed to treat the path as part of the pattern? I would rather think it should use the current directory as a starting point, and then process the pattern only.

(Attempt to summarize): The glob function acts like it’s getting c:\\[test]\\* as a match pattern, and is trying to match either c:\t\*, c:\e\*, or c:\s\*. But the pattern is actually * and it shouldn’t be trying to match any of that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:49:50+00:00Added an answer on June 3, 2026 at 3:49 pm

    This seems to be covered as an issue in this bug report on php.net: https://bugs.php.net/bug.php?id=33047

    The last post on that thread is about it not being a bug, but an issue from how glob treats brackets, as part of the regular expression. I’m not sure I agree. It seems you can work around this, unless you cannot move up into the parent folder.

    If you remove the first requirement of being in the inside [test] folder, you can get the file listing by using a syntax like below:

    chdir('..');
    $glob = glob("[[]test[]]/*");
    

    Given these complications, I would recommend not using the glob function if you are running into issues on windows machines, and look at other file listing functions like readdir.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine the following: User goes to script ( http://sample.org/test.php ), Script sends an HTTP
32-bit mongo 2.0.1 on a windows XP machine //script filename: test.js (one line shell
The following C++ program crashes on my Windows XP machine with a message Abnormal
I am installing ant on a Windows XP machine, and am following the instructions
On my Windows machine -- I typically test different versions of Internet Explorer using
Why do some processes started at the command line on my Windows machine block/buffer
Howdy, I'm writing a batch script that will run on a Windows XP machine.
How can I get the current Windows time in a PHP script? Using time()
I wrote the following Nant script on my Vista dev machine and was pleased
I just got PHP-CLI working on my Windows machine so I could create scripts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.