Newsgroups: comp.lang.perl.moderated
From: Dave Tweed <dtw...@acm.org>
Date: Thu, 23 Aug 2001 21:11:42 -0400
Local: Thurs, Aug 23 2001 9:11 pm
Subject: Re: Traversal of a directory tree with housekeeping per directory
Michael Rolfe wrote: Again, I offer my simple tree-walker as an alternative to File::Find. The > I want to traverse a tree but, within each directory, I need to do a fair > amount of housekeeping. In particular, I need to read through all the files > in the directory before I have the information I need to start doing the > housekeeping in that directory. compact version recurses into subdirectories as it finds them, so it may not quite meet your requirements. The full version separates the names before processing any of them, so you can do something to all the files, do some housekeeping, and then start recursing into the subdirectories. Note that in either case, unlike File::Find, these functions do not chdir() Enjoy! -- Dave Tweed =========================================================================== == #!perl -w &process_directory ('/path/to/root'); # compact version sub process_directory { # get all of the names from the directory, excluding "." and ".." # the sort is optional } sub process_file { my ($path) = @_; # whatever ... } =========================================================================== == #!perl -w &process_directory ('/path/to/root'); # full version sub process_directory { # get the names out of the current directory and separate them into # process all the files # do any housekeeping here, before recursing into subdirectories # process all the subdirectories } sub process_file { my ($path) = @_; # whatever ... } # customize the filtering and sorting of names here sub read_directory { # get all of the names from a directory, excluding "." and ".." # optional - filter out all other names starting with '.' # optional - sort the names @names; } =========================================================================== == You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||