On 05/23/00, "Garrick Staples <[EMAIL PROTECTED]>" wrote:
> You just want each page to have the links for the files/directories in that
> immediate directory?  np...

>From this part of his description, I assume he also wants to list
all the directories at the same level in the parent directory:

> > > one.html which contains something like
> > > one
> > >     - a
> > >     - b
> > > two
> > > three

I've been thinking far too much about this, so although
I like Garricks solution for what it does, here's mine
for what I think it's supposed to do (even though you
could probably modify Garrick's to do the same thing):
#!/usr/bin/perl -l -w

use File::Find;

my $top_dir="/home/dougw/tmp/root";

my (%children, %parent);
get_children($top_dir);
find(\&mk_tree, $top_dir);

chdir $top_dir or die "Can't cd to $top_dir: $!";
open(INDEX, ">index.html") or die "Can't write to index.html in $top_dir: 
$!";
print_children($top_dir);
close INDEX;
chdir ".." or die "Can't cd to $top_dir/..: $!";
find(\&print_tree, $top_dir);

sub mk_tree {
 return if $_ eq "." or ! -d;

 get_children($File::Find::name);
 $parent{$File::Find::name}=$File::Find::dir;
}

sub get_children {
 my $path = shift;
 (my $dir = $path) =~ s|.*/||;
 opendir(SUBDIR, $dir) or die "Can't open $dir: $!";
 for my $sub_dir (grep { -d "$dir/$_" && !/^\.\.?\z/ } readdir SUBDIR) {
  push @{$children{$path}}, $sub_dir;
 }
 closedir SUBDIR;
}

sub print_tree {
 return if $_ eq "." or ! -d;
 chdir $_ or die "Can't cd to $File::Find::name: $!";
 open(INDEX, ">index.html")
  or die "Can't open index.html in $File::Find::name: $!";
 for my $dir (@{$children{$parent{$File::Find::name}}}) {
  print INDEX $dir;
  print_children($File::Find::name) if $dir eq $_;
 }
 close INDEX;
 chdir ".." or die "Can't cd to $File::Find::name/..: $!";
}

sub print_children {
 my $dir = shift;
 for my $child (@{$children{$dir}}) {
  print INDEX "- $child";
 }
}

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to