#!/usr/bin/perl -w use strict; use File::Find; my @searchdirs = ( ".", "c:/", "d:/" ); # And here is the regular expression to check # for an unwanted directory. In my example, # I chose the directory name .CVS as an # "unwanted" directory my $unwanteddir = ".CVS"; find( sub { # In this function,we decide what to do # with each thing we find. We find both, # files and directories. # first check, if we have a directory : if (-d $File::Find::name) { print "Directory : $File::Find::name\n"; # Now we check if it is unwanted : if ($File::Find::name =~ m!(^|/)$unwanteddir(/|$)!) { print "In unwanted directory.\n"; # And tell File::Find that we don't want to look at # this directory $File::Find::prune = 1; }; } elsif (-f $File::Find::name) { # It's a file print "File : $File::Find::name\n"; } else { # It's a symlink or something else we can't handle }; } , @subdirs ); # here is the end of the find() function call