Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Directory Tree

by Kanji (Parson)
on Mar 26, 2004 at 18:09 UTC ( [id://340095]=note: print w/replies, xml ) Need Help??


in reply to Directory Tree..Thanks

If you're using a version of File::Find that supports pre- and postprocess hooks (>= Perl 5.6, IIRC) then you can do something like...

#!perl -l # TESTED WITH v5.6.1 (MSWin32-x86-multi-thread) ONLY! require 5.006; use strict; use File::Find 'find'; my $INDENT_DELIM = ' '; my $DEPTH = 0; find( { wanted => \&wanted, preprocess => \&pre, postprocess => \&post, }, @ARGV ? @ARGV : "." ); sub pre { print indent( '<li id="folder">' . $_ . '</li>' ); print indent( '<ul>' ); $DEPTH++; @_; } sub post { $DEPTH--; print indent( '</ul>' ); } sub wanted { return if -d; print indent( '<li>' . $_ . '</li>' ); } sub indent { return $INDENT_DELIM x $DEPTH . $_[0]; }

    --k.


Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-25 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found