[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Recursively visit all files in a directo





Jim Correia wrote:
> 
> On 12:27 PM 12/27/00 Dan Baker <dan@dtbakerprojects.com> wrote:
> 
> > read the module docs on File::Find
> > it is part of the standard install
> >
> > you can generate a list, or work on each file "on-the-fly" as it
> > recurses thru defined dirs with defined match patterns.
> 
> Thanks - I will look at that...
-------------------------

this is a little script I save to remind me how to use it:

#!/usr/bin/perl -w

use File::Find;

my @TOP =                     # top level directories to search
  qw( ./ );

# --------------- executable --------------------------------
my $ExitFlag = 0 ;

find (
   sub { # this sub is executed for each listing traversed

        print " $File::Find::name last modified
".localtime((stat($_))[9])." \n";

   }, 
@TOP);

print "--- done --- " ;
sleep 30;
# -----------------------------------------------------------

=head1 function documentation summary

	Overview:
	the find() routine basically traverses a dir tree beginning at defined
	start dirs, and loops thru all listings. You write a sub{} to process
each 
	list item. You can build hashes or arrays to use after the traversel is
complete,
	or "do stuff" in-line.

	Usage:
	find( sub{ # do stuff for each listing }, @TopDirPaths );

	Info available within sub during loop thru Dir listings:
	-------------------------------------------------------
	# $File::Find::dir contains the current directory path.
	# $File::Find::name contains the current full pathname.
	# $_ is the basename of the current listing.

	How to control the looping:
	--------------------------
	# you can test $_ , $File::Find::name , $File::Find::dir 
	with patternmatching, expressions, or whatever...
	
	# skipping the remainder of the sub(), and moving to the next in the
list:
		return;

	# processing the current dir may be pruned from the loop so that no
more
	  of the listings within the dir get processed with:
		$File::Find::prune = 1 ; return;

	# note that there is no direct way to blow out of the find() 
	gracefully in the middle because it is chdir()ing, but if
	you set a flag and prune everything afterwards, you get out 
	pretty quickly. This may be useful when you were looking for a
	specific file,and dont need to look further once it has been found.
        

=cut

1;

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org