#!/usr/bin/perl sub crawl($); sub add_slash($); sub get_prefix(); sub make_full_path($$); $main::level = 0; # count depth level for indentation sub crawl($) { my $dir = shift; $dir = $dir.add_slash($dir); my $file; my $html = ""; $main::level++; chdir($dir) or (warn "Cannot chdir to '$dir': $!" and return); opendir(DIR, $dir) or (warn "Cannot open '$dir': $!" and return); my @contents = readdir(DIR); closedir(DIR); # Links may be ignored completely: if( $conf::ignore_links ) { @contents = grep { not -l } @contents; } # No hidden files and ".." directories: @contents = grep {!/^\./} @contents; # Get directories: my @dirs = grep {-d} @contents; # Get files: my @files = grep {-f} @contents; my $prefix = get_prefix(); # Go through all directories in this directory: foreach my $d (sort(@dirs)) { #next if ( ! include_file($d, $dir) ); my $this_dir = make_full_path($dir, $d); $html .= crawl($this_dir); } $main::level--; return $html; } sub add_slash($) { my $file = shift; if( -d $file && $file !~ m/\/$/ ) { return "/"; } else { return ""; } } sub get_prefix() { my $prefix = "\t" x $main::level; return $prefix; } sub make_full_path($$) { my $dir = shift; my $file = shift; my $full_path; $full_path = $dir."/".$file; $full_path =~ s/\/\//\//og; return $full_path; } crawl("/home/kake26");