4 # &find('/foo','/bar');
7 # where wanted does whatever you want. $dir contains the
8 # current directory name, and $_ the current filename within
9 # that directory. $name contains "$dir/$_". You are cd'ed
10 # to $dir when the function is called. The function may
11 # set $prune to prune the tree.
13 # This library is primarily for find2perl, which, when fed
15 # find2perl / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune
17 # spits out something like this
21 # (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
25 # ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
32 foreach $topdir (@_) {
33 (($topdev,$topino,$topmode,$topnlink) = stat($topdir))
34 || (warn("Can't stat $topdir: $!\n"), next);
37 ($dir,$_) = ($topdir,'.');
41 &finddir($topdir,$topnlink);
44 warn "Can't cd to $topdir: $!\n";
48 unless (($dir,$_) = $topdir =~ m#^(.*/)(.*)$#) {
49 ($dir,$_) = ('.', $topdir);
52 chdir $dir && &wanted;
59 local($dir,$nlink) = @_;
60 local($dev,$ino,$mode,$subcount);
63 # Get the list of files in the current directory.
65 opendir(DIR,'.') || (warn "Can't open $dir: $!\n", return);
66 local(@filenames) = readdir(DIR);
69 if ($nlink == 2) { # This dir has no subdirectories.
78 else { # This dir has subdirectories.
79 $subcount = $nlink - 2;
86 if ($subcount > 0) { # Seen all the subdirs?
88 # Get link count and check for directoriness.
90 ($dev,$ino,$mode,$nlink) = lstat($_) unless $nlink;
94 # It really is a directory, so do it recursively.
96 if (!$prune && chdir $_) {
97 &finddir($name,$nlink);