--- nfo/perl/libs/libp.pm 2002/07/19 18:13:50 1.3 +++ nfo/perl/libs/libp.pm 2002/08/16 19:06:39 1.4 @@ -1,8 +1,11 @@ ################################# # -# $Id: libp.pm,v 1.3 2002/07/19 18:13:50 cvsjoko Exp $ +# $Id: libp.pm,v 1.4 2002/08/16 19:06:39 cvsjoko Exp $ # # $Log: libp.pm,v $ +# Revision 1.4 2002/08/16 19:06:39 cvsjoko +# + sub getDirList +# # Revision 1.3 2002/07/19 18:13:50 cvsjoko # no message # @@ -27,6 +30,7 @@ stripHtml stripSpaces stripNewLines toReal trim croak array_getDifference + getDirList ); use strict; @@ -47,6 +51,8 @@ use Carp; +use DirHandle; + ######################################## @@ -127,4 +133,75 @@ return $res->{diff}; } + +# ============================================= +# "global" vars used in directory-recursive-parsing +my $dirlist_buf; +my @dirlist_path; +my $dirlist_base; + +sub entry_callback { + + my $entry = shift; + + # CHECKS + # dont't use this: + if ($entry eq '.' || $entry eq '..') { return; } + + # PREPARE + # prepare path to current entry + my $cur_entry = join('/', @dirlist_path, $entry); + # prepare path to current entry (absolute) + my $cur_entry_abs = join('/', $dirlist_base, @dirlist_path, $entry); + + # ENTRY + # add current entry to buffer + $dirlist_buf .= $cur_entry . "\n"; + + # (SUB-)DIRECTORY + # check if current entry is a (sub-)directory ... + if (-d $cur_entry_abs) { + push @dirlist_path, $cur_entry; + # ... and parse this (recursion here!!!) + iterate_path($cur_entry_abs); + pop @dirlist_path; + } +} + +sub iterate_path { + + my $path = shift; + + # create new "DirHandle"-object + my $d = new DirHandle $path; + if (defined $d) { + + # iterate through all entries in $path ($d->read) and call out entry-handler on each entry + while (defined(my $line = $d->read)) { + entry_callback($line); + } + + undef $d; + } +} + +sub getDirList { + + $dirlist_base = shift; + + # reset vars + $dirlist_buf = ''; + @dirlist_path = (); + + # start parsing file-structure + iterate_path($dirlist_base); + + # return complete list of directory-content including files and subdirs + # entries are newline (\n) - seperated + return $dirlist_buf; + +} +# ============================================= + + 1;