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

Re: [MacPerl] Recursively visit all files in a directory?



 >What is the easiest way to do this?

You'd probably be looking at File::Find. There are some examples on how to 
use it here:

    http://www.perlmonks.com/index.pl?node_id=9799&lastnode_id=864


 >I could do it myself but surely there must already be a module that does
 >this.

This is how I do it "myself":

my $ALLOWED_EXTENSIONS = "shtml";
my @DIRS = "/home/";
my @IGNORE = ("vecna", "index");

while (@DIRS) {
    my $dir = shift (@DIRS);
    opendir (DIR, "$dir"); my @files = readdir (DIR); closedir (DIR);

    foreach my $file (@files) {
       $dir =~ s/\/$//s;

       if ((-d "$dir/$file") && ($file ne ".") && ($file ne "..")) {
          push @DIRS, "$dir/$file"; next;
       }

       next if ($file !~ /(\.$ALLOWED_EXTENSIONS)$/i);

       #### do stuff to file here ####
    }
}

Morbus Iff
.sig on other machine.
http://www.disobey.com/
http://www.gamegrene.com/


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