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

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 . "https://stackoverflow.com/" . $result)) {
        //code to use if directory
    }
}

Leave a Comment