9 @EXPORT = qw(find finddepth $name $dir);
14 # find(\&wanted, '/foo','/bar');
17 # where wanted does whatever you want. $dir contains the
18 # current directory name, and $_ the current filename within
19 # that directory. $name contains "$dir/$_". You are cd'ed
20 # to $dir when the function is called. The function may
21 # set $prune to prune the tree.
23 # This library is primarily for find2perl, which, when fed
25 # find2perl / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune
27 # spits out something like this
31 # (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
35 # ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
40 # Set the variable $dont_use_nlink if you're using AFS, since AFS cheats.
45 foreach $topdir (@_) {
46 (($topdev,$topino,$topmode,$topnlink) = stat($topdir))
47 || (warn("Can't stat $topdir: $!\n"), next);
50 ($dir,$_) = ($topdir,'.');
53 ($fixtopdir = $topdir) =~ s,/$,, ;
54 $fixtopdir =~ s/\.dir$// if $Is_VMS; ;
55 &finddir($wanted,$fixtopdir,$topnlink);
58 warn "Can't cd to $topdir: $!\n";
62 unless (($dir,$_) = fileparse($topdir)) {
63 ($dir,$_) = ('.', $topdir);
66 chdir $dir && &$wanted;
73 local($wanted,$dir,$nlink) = @_;
74 local($dev,$ino,$mode,$subcount);
77 # Get the list of files in the current directory.
79 opendir(DIR,'.') || (warn "Can't open $dir: $!\n", return);
80 local(@filenames) = readdir(DIR);
83 if ($nlink == 2 && !$dont_use_nlink) { # This dir has no subdirectories.
92 else { # This dir has subdirectories.
93 $subcount = $nlink - 2;
100 if ($subcount > 0 || $dont_use_nlink) { # Seen all the subdirs?
102 # Get link count and check for directoriness.
104 ($dev,$ino,$mode,$nlink) = ($Is_VMS ? stat($_) : lstat($_))
105 unless ($nlink || $dont_use_nlink);
109 # It really is a directory, so do it recursively.
111 if (!$prune && chdir $_) {
112 $name =~ s/\.dir$// if $Is_VMS;
113 &finddir($wanted,$name,$nlink);
126 # finddepth(\&wanted, '/foo','/bar');
129 # where wanted does whatever you want. $dir contains the
130 # current directory name, and $_ the current filename within
131 # that directory. $name contains "$dir/$_". You are cd'ed
132 # to $dir when the function is called. The function may
133 # set $prune to prune the tree.
135 # This library is primarily for find2perl, which, when fed
137 # find2perl / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune
139 # spits out something like this
143 # (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
147 # ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
155 foreach $topdir (@_) {
156 (($topdev,$topino,$topmode,$topnlink) = stat($topdir))
157 || (warn("Can't stat $topdir: $!\n"), next);
159 if (chdir($topdir)) {
160 ($fixtopdir = $topdir) =~ s,/$,, ;
161 $fixtopdir =~ s/\.dir$// if $Is_VMS;
162 &finddepthdir($wanted,$fixtopdir,$topnlink);
163 ($dir,$_) = ($fixtopdir,'.');
168 warn "Can't cd to $topdir: $!\n";
172 unless (($dir,$_) = fileparse($topdir)) {
173 ($dir,$_) = ('.', $topdir);
175 chdir $dir && &$wanted;
182 my($wanted,$dir,$nlink) = @_;
183 my($dev,$ino,$mode,$subcount);
186 # Get the list of files in the current directory.
188 opendir(DIR,'.') || warn "Can't open $dir: $!\n";
189 my(@filenames) = readdir(DIR);
192 if ($nlink == 2 && !$dont_use_nlink) { # This dir has no subdirectories.
201 else { # This dir has subdirectories.
202 $subcount = $nlink - 2;
208 if ($subcount > 0 || $dont_use_nlink) { # Seen all the subdirs?
210 # Get link count and check for directoriness.
212 ($dev,$ino,$mode,$nlink) = ($Is_VMS ? stat($_) : lstat($_));
216 # It really is a directory, so do it recursively.
218 if (!$prune && chdir $_) {
219 $name =~ s/\.dir$// if $Is_VMS;
220 &finddepthdir($wanted,$name,$nlink);
231 if ($Config{'osname'} eq 'VMS') {