Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Directory Tree Structure

by mickep76 (Beadle)
on Oct 05, 2009 at 09:19 UTC ( [id://799203]=note: print w/replies, xml ) Need Help??


in reply to Directory Tree Structure

Hi

This is one example of using recursion to solve it.

use strict; my $path = '/var/www/html'; print "<ul>\n"; recurse_path($path, " "); print "</ul>\n"; sub recurse_path { my $path = shift; my $padding = shift; my $dir = $path; $dir =~ s/.*\///g; print "$padding<li><a href=\"$path\">$dir</a>\n"; my $has_subdir = 0; foreach(glob("$path/*")) { if(-d $_ && ! $has_subdir) { print "$padding<ul>\n"; $has_subdir = 1; recurse_path($_, $padding . " ") } elsif(-d $_) { recurse_path($_, $padding . " ") } } if($has_subdir) { print "$padding</ul>\n" } }

Replies are listed 'Best First'.
Re^2: Directory Tree Structure
by Lady_Aleena (Priest) on Mar 21, 2010 at 23:10 UTC

    Hello mickep76,

    I know it's been a few months since you posted this, but I just saw it. FYI, you aren't closing the list items (</li>). I would give it a shot, but your recursion is confusing me a bit.

    Have a nice day!
    Lady Aleena

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://799203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-29 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found