Hi Monks!
How could a make a directory print different if found? Here are more details
All that has to be done is to give a path to be search on $dir, and this code will print a directory tree out of it, but I would like to see if inside of the given path on $dir more directories are found I would like to see them highlighted for further display options.
Here is the code:
#!/perl/bin/perl
use warnings;
use strict;
use File::Slurp::Tree;
use CGI qw(:header);
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
# The tree datastructure is a hash of hashes. The keys of
# each hash are names of directories or files. Directories
# have hash references as their value, files have a scalar
# which holds the contents of the file.
my $dir = "c:/progra~1/apache~1/apache2/cgi-bin/test";
my %tree;
my $tree = slurp_tree($dir);
my $depth = 0;
print header();
print_keys($tree);
sub print_keys {
my $href = shift;
$depth++;
foreach ( keys %$href ) {
if(-d $_){ print "<b>Dir exists= $_</b><br>";}
print '****' x $depth, "<input type=checkbox> --$_<br>\n";
print_keys( $href->{$_} ) if ref $href->{$_} eq 'HASH';
}
$depth--;
}
Thanks a lot!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|