Using scandir() to find folders in a directory (PHP)

前端 未结 9 2097
Happy的楠姐
Happy的楠姐 2020-12-02 13:11

I am using this peice of code:

$target = \'extracted/\' . $name[0];  
$scan = scandir($target);

To scan the directory of a folder which is

9条回答
  •  生来不讨喜
    2020-12-02 14:07

    To determine whether or not you have a folder or file use the functions is_dir() and is_file()

    For example:

    $path = 'extracted/' . $name[0];
    $results = scandir($path);
    
    foreach ($results as $result) {
        if ($result === '.' or $result === '..') continue;
    
        if (is_dir($path . '/' . $result)) {
            //code to use if directory
        }
    }
    

提交回复
热议问题