Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save faisal-ibrahim/630241578d446a280c8c31e3cac5cd52 to your computer and use it in GitHub Desktop.

Select an option

Save faisal-ibrahim/630241578d446a280c8c31e3cac5cd52 to your computer and use it in GitHub Desktop.

Revisions

  1. faisal-ibrahim created this gist Mar 27, 2019.
    33 changes: 33 additions & 0 deletions recursiveDirectoryListingSolutions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <?php
    /**
    * Function for recursive directory file list search as an array.
    *
    * @param mixed $dir Main Directory Path.
    *
    * @return array
    */
    function listFolderFiles($dir)
    {
    $fileInfo = scandir($dir);
    $allFileLists = [];

    foreach ($fileInfo as $folder) {
    if ($folder !== '.' && $folder !== '..') {
    if (is_dir($dir . DIRECTORY_SEPARATOR . $folder) === true) {
    $allFileLists[$folder] = listFolderFiles($dir . DIRECTORY_SEPARATOR . $folder);
    } else {
    $allFileLists[$folder] = $folder;
    }
    }
    }

    return $allFileLists;
    }//end listFolderFiles()


    $dir = listFolderFiles('your searching directory path ex:-F:\xampp\htdocs\abc');
    echo '<pre>';
    print_r($dir);
    echo '</pre>'

    ?>