/[cvs]/nfo/perl/libs/libp.pm
ViewVC logotype

Diff of /nfo/perl/libs/libp.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by cvsjoko, Fri Jul 19 18:13:50 2002 UTC revision 1.4 by cvsjoko, Fri Aug 16 19:06:39 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.4  2002/08/16 19:06:39  cvsjoko
7    #  + sub getDirList
8    #
9  #  Revision 1.3  2002/07/19 18:13:50  cvsjoko  #  Revision 1.3  2002/07/19 18:13:50  cvsjoko
10  #  no message  #  no message
11  #  #
# Line 27  require Exporter; Line 30  require Exporter;
30      stripHtml stripSpaces stripNewLines toReal trim      stripHtml stripSpaces stripNewLines toReal trim
31      croak      croak
32      array_getDifference      array_getDifference
33        getDirList
34  );  );
35    
36  use strict;  use strict;
# Line 47  use POSIX qw(strftime); Line 51  use POSIX qw(strftime);
51    
52  use Carp;  use Carp;
53    
54    use DirHandle;
55    
56    
57  ########################################  ########################################
58    
# Line 127  sub array_getDifference { Line 133  sub array_getDifference {
133    return $res->{diff};    return $res->{diff};
134  }  }
135    
136    
137    # =============================================
138    # "global" vars used in directory-recursive-parsing
139    my $dirlist_buf;
140    my @dirlist_path;
141    my $dirlist_base;
142    
143    sub entry_callback {
144    
145      my $entry = shift;
146    
147      # CHECKS
148      # dont't use this:
149      if ($entry eq '.' || $entry eq '..') { return; }
150    
151      # PREPARE
152      # prepare path to current entry
153      my $cur_entry = join('/', @dirlist_path, $entry);
154      # prepare path to current entry (absolute)
155      my $cur_entry_abs = join('/', $dirlist_base, @dirlist_path, $entry);
156    
157      # ENTRY
158      # add current entry to buffer
159      $dirlist_buf .= $cur_entry . "\n";
160    
161      # (SUB-)DIRECTORY
162      # check if current entry is a (sub-)directory ...
163      if (-d $cur_entry_abs) {
164        push @dirlist_path, $cur_entry;
165        # ... and parse this (recursion here!!!)
166        iterate_path($cur_entry_abs);
167        pop @dirlist_path;
168      }
169    }
170    
171    sub iterate_path {
172    
173      my $path = shift;
174    
175      # create new "DirHandle"-object
176      my $d = new DirHandle $path;
177      if (defined $d) {
178    
179        # iterate through all entries in $path ($d->read) and call out entry-handler on each entry
180        while (defined(my $line = $d->read)) {
181          entry_callback($line);
182        }
183    
184        undef $d;
185      }
186    }
187    
188    sub getDirList {
189    
190      $dirlist_base = shift;
191    
192      # reset vars
193      $dirlist_buf = '';
194      @dirlist_path = ();
195    
196      # start parsing file-structure
197      iterate_path($dirlist_base);
198    
199      # return complete list of directory-content including files and subdirs
200      # entries are newline (\n) - seperated
201      return $dirlist_buf;
202    
203    }
204    # =============================================
205    
206    
207  1;  1;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed