CSV file to flat array with materialized path
<p>I have CSV file which contains a list of files and directories:</p>

<pre><code>Depth;Directory;
0;bin
1;basename
1;bash
1;cat
1;cgclassify
1;cgcreate
0;etc
1;aliases
1;audit
2;auditd.conf
2;audit.rules
0;home
....
</code></pre>

<p>Each line depends on the above one (for the depth param)</p>

<p>I would like to create an array like this one in order to store it into my <a href="http://www.mongodb.org/display/DOCS/Trees+in+MongoDB#TreesinMongoDB-MaterializedPaths%28FullPathinEachNode%29" rel="nofollow">MongoDB collection with Materialized Paths</a></p>

<pre><code>$directories = array(
  array('_id' =&gt; null,
        'name' =&gt; "auditd.conf",
        'path' =&gt; "etc,audit,auditd.conf"),
  array(....)
);
</code></pre>

<p>I don't know how to process...
Any ideas?</p>

<p><strong>Edit 1</strong>: 
I'm not really working with directories - it's an example, so I cannot use FileSystems functions or FileIterators.</p>

<p><strong>Edit 2</strong>:
From this CSV file, I'm able to create a JSON nested array:</p>

<pre><code>function nestedarray($row){
    list($id, $depth, $cmd) = $row;

    $arr = &amp;$tree_map;

        while($depth--) {
         end($arr ); 
         $arr = &amp;$arr [key($arr )];
    }

    $arr [$cmd] = null;             

}
</code></pre>

<p>But i'm not sure it's the best way to proceed...</p>
