0

I have a directory structure as shown below.

C:\xampp\htdocs\rosoka\file
----- 2018-03-02
-------------test1.json
-------------test2.json
----- 2018-03-03
-------------test3.json
-------------test4.json

I want all my folders to be the key of an array associated like this on the last trace outside the function

Array ( [C:/xampp/htdocs/rosoka/file] => Array ( )) 
Array ( [C:/xampp/htdocs/rosoka/file/2018-03-02] => Array ()) 
Array ( [C:/xampp/htdocs/rosoka/file/2018-03-03] => Array ()) 

this is my source code please help me.

<?php
    $no_entity = array();
    listFolderFiles("C:/xampp/htdocs/rosoka/file", $no_entity);
function listFolderFiles($dir, $no_entity){
        echo "<br>";
    if (array_key_exists($dir, $no_entity)) {
        echo "why no result here??? T_T";
    } else {
        $no_entity[$dir] = array();
        print_r($no_entity);
    }
    $real_path = "C:/xampp/htdocs/rosoka/file";
    $real_path =  str_replace($real_path,"",$dir);
    set_time_limit (3000000);
    ini_set('memory_limit', '-1');
    $ffs = scandir($dir);
    unset($ffs[array_search('.', $ffs, true)]);
    unset($ffs[array_search('..', $ffs, true)]);
    $ffs = array_values($ffs);
    if (count($ffs) < 1)
        return;
    foreach($ffs as $ff){
       if(is_dir($dir.'/'.$ff)) {
            listFolderFiles($dir.'/'.$ff, $no_entity); 
        } else { 
        }
    }
}
    //  "WHERE MY ARRAY T_T";
    var_dump($no_entity);   
?>

(for testing ekstract to htdocs) https://drive.google.com/file/d/1dtXbQFrWoD0dQFOb-2YRqcH4eKPUTzZ9/view?usp=sharing

1 Answers1

1

Without some better examples of your folder structure and what you are wanting from it, this is my best guess.

This will take folders found in the directory and create an array like you have posted.

$path = 'C:/xampp/htdocs/rosoka/file';
$dir = glob($path . '/*', GLOB_ONLYDIR);

foreach($dir as $d => $val){

  $results[][$val]  = array();

}

print_r($results);
Joseph_J
  • 3,654
  • 2
  • 13
  • 22