#!/perl/bin/perl -w use strict; use CGI qw(:header); use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; my $show = param("show"); my $input_dir = "/cgi-bin/cars"; print header(); print "<html> <head><title>Tree</title> </head>"; MAIN: { my @tree; dirwalk ($input_dir,\@tree); printtree(\@tree); print "</OL>\n"; } sub dirwalk { my ($dir,$tree) = @_ ; push @{$tree},($dir =~ m#([^/]+$)#); opendir DIR, $dir || die "Couldnt open $dir - $!\n"; my @entries = grep !/^\.{1,2}$/, readdir(DIR); closedir (DIR); foreach my $item (@entries) { my $fullpath = "$dir/$item"; if ( -d $fullpath ) { dirwalk ( $fullpath,\@{$tree->[@{$tree}]}); } else { push @{$tree},$item; } } } sub printtree { my $tree = shift; my $c=-1; print "<LI><a href=\"tree.pl?show=true\"><img src=dir.gif border=0>& +nbsp;",shift @{$tree},"</a>/53<br>\n"; print "qqq<OL>\n"; foreach my $item ( @{$tree} ) { #print "<b>$item</b>"; $c++; if (ref $item eq "ARRAY" ) { printtree($item); } else { print "<LI><input type=checkbox> \n"; print $item,"^$c-64\n"; } } print "</OL>"; }
In reply to Displaying Sub Directories by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |