![]() |
|
Keep It Simple, Stupid | |
PerlMonks |
perlman:File::Findby root (Monk) |
on Dec 23, 1999 at 00:51 UTC ( #1206=perlfunc: print w/replies, xml ) | Need Help?? |
File::FindSee the current Perl documentation for File::Find. Here is our local, out-dated (pre-5.6) version: ![]() find - traverse a file tree finddepth - traverse a directory structure depth-first
![]()
use File::Find; find(\&wanted, '/foo','/bar'); sub wanted { ... }
use File::Find; finddepth(\&wanted, '/foo','/bar'); sub wanted { ... }
The first argument to
Currently the only other supported key for the above hash is
The
File::Find assumes that you don't alter the
This library is useful for the
find2perl / -name .nfs\* -mtime +7 \ -exec rm -f {} \; -o -fstype nfs -prune produces something like:
sub wanted { /^\.nfs.*$/ && (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && int(-M _) > 7 && unlink($_) || ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) && $dev < 0 && ($File::Find::prune = 1); } Set the variable $File::Find::dont_use_nlink if you're using AFS, since AFS cheats.
Here's another interesting wanted function. It will find all symlinks that don't resolve:
sub wanted { -l && !-e && print "bogus link: $File::Find::name\n"; }
BUGSThere is no way to make find or finddepth follow symlinks. |
|