home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl502b.zip / eg / van / empty next >
Text File  |  1994-10-18  |  793b  |  46 lines

  1. #!/usr/bin/perl
  2.  
  3. # $RCSfile: empty,v $$Revision: 4.1 $$Date: 92/08/07 17:20:50 $
  4.  
  5. # This script empties a trashcan.
  6.  
  7. $recursive = shift if $ARGV[0] eq '-r';
  8.  
  9. @ARGV = '.' if $#ARGV < 0;
  10.  
  11. chop($pwd = `pwd`);
  12.  
  13. dir: foreach $dir (@ARGV) {
  14.     unless (chdir $dir) {
  15.     print stderr "Can't find directory $dir: $!\n";
  16.     next dir;
  17.     }
  18.     if ($recursive) {
  19.     do cmd('find . -name .deleted -exec /bin/rm -rf {} ;');
  20.     }
  21.     else {
  22.     if (-d '.deleted') {
  23.         do cmd('rm -rf .deleted');
  24.     }
  25.     else {
  26.         if ($dir eq '.' && $pwd =~ m|/\.deleted$|) {
  27.         chdir '..';
  28.         do cmd('rm -rf .deleted');
  29.         }
  30.         else {
  31.         print stderr "No trashcan found in directory $dir\n";
  32.         }
  33.     }
  34.     }
  35. }
  36. continue {
  37.     chdir $pwd;
  38. }
  39.  
  40. # force direct execution with no shell
  41.  
  42. sub cmd {
  43.     system split(' ',join(' ',@_));
  44. }
  45.  
  46.