Glob is not working when directory name with special characters like square brackets “[ ]”

前端 未结 4 1398
长发绾君心
长发绾君心 2021-01-13 01:47

I have issue while using glob function when path directory with square brackets.

// Example 1 - working
$path = \'temp\'. DIRECTORY_SEPARATOR .\'dir - name\'         


        
4条回答
  •  误落风尘
    2021-01-13 02:13

    Thanks for all of you.

    I got exact solution for my query. below code is a working for me

    $path = 'temp'. DIRECTORY_SEPARATOR .'dir - [name]';
    $path = str_replace('[', '\[', $path);
    $path = str_replace(']', '\]', $path);
    $path = str_replace('\[', '[[]', $path);
    $path = str_replace('\]', '[]]', $path);
    $files = glob($path . DIRECTORY_SEPARATOR . '*.txt');
    // List files
    echo '
    ';
        print_r($files);
    echo '
    ';

提交回复
热议问题