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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.