Beispiel: mkfiledb und findfile II

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

mkfiledb.pl
sub scan { # scan and return all sub directories
   my ($path) = @_;
   my ($file, @dirs) = ();
   my $dir = new IO::Dir $path;
   my $dbpath = $path; $dbpath =~ s{^\./}{};
   return () unless defined $dir;
   while (defined($file = $dir->read)) {
      next if $file =~ /^\.\.?$/;
      if (defined($db{$file})) {
         $db{$file} .= "\0" . $dbpath;
      } else {
         $db{$file} = $dbpath;
      }
      next if -l $file; # skip symbolic links
      push(@dirs, "$path/$file") if -d "$path/$file";
   }
   $dir->close;
   return @dirs;
}

sub descend {
   my ($path) = @_;
   foreach my $dir (scan($path)) {
      descend($dir);
   }
}

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1996, 1998, 1999, 2000 Andreas Borchert, in HTML konvertiert am 07.02.2000