Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. # Usage:
  2. # require "find.pl";
  3. #
  4. # &find('/foo','/bar');
  5. #
  6. # sub wanted { ... }
  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.
  12. #
  13. # This library is primarily for find2perl, which, when fed
  14. #
  15. # find2perl / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune
  16. #
  17. # spits out something like this
  18. #
  19. # sub wanted {
  20. # /^\.nfs.*$/ &&
  21. # (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
  22. # int(-M _) > 7 &&
  23. # unlink($_)
  24. # ||
  25. # ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
  26. # $dev < 0 &&
  27. # ($prune = 1);
  28. # }
  29. #
  30. # Set the variable $dont_use_nlink if you're using AFS, since AFS cheats.
  31. use File::Find ();
  32. *name = *File::Find::name;
  33. *prune = *File::Find::prune;
  34. *dir = *File::Find::dir;
  35. *topdir = *File::Find::topdir;
  36. *topdev = *File::Find::topdev;
  37. *topino = *File::Find::topino;
  38. *topmode = *File::Find::topmode;
  39. *topnlink = *File::Find::topnlink;
  40. sub find {
  41. &File::Find::find(\&wanted, @_);
  42. }
  43. 1;