home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1997 / CT_SW_97.ISO / pc / software / entwickl / win95 / pw32i306.exe / eg / van / vanish < prev   
Text File  |  1994-10-18  |  1KB  |  66 lines

  1. #!/usr/bin/perl
  2.  
  3. # $RCSfile: vanish,v $$Revision: 4.1 $$Date: 92/08/07 17:20:54 $
  4.  
  5. sub it {
  6.     if ($olddir ne '.') {
  7.     chop($pwd = `pwd`) if $pwd eq '';
  8.     (chdir $olddir) || die "Directory $olddir is not accesible";
  9.     }
  10.     if (!-d .deleted) {
  11.     print `mkdir .deleted; chmod 775 .deleted`;
  12.     die "You can't remove files from $olddir" if $?;
  13.     }
  14.     $filelist =~ s/ $//;
  15.     $filelist =~ s/#/\\#/g;
  16.     if ($filelist !~ /^[ \t]*$/) {
  17.     open(lastcmd,'>.deleted/.lastcmd');
  18.     print lastcmd $filelist,"\n";
  19.     close(lastcmd);
  20.     print `/bin/mv $startfiles$filelist .deleted$force`;
  21.     }
  22.     if ($olddir ne '.') {
  23.     (chdir $pwd) || die "Can't get back to original directory $pwd: $!\n";
  24.     }
  25. }
  26.  
  27. while ($ARGV[0] =~ /^-/) {
  28.     $_ = shift;
  29.     /^-f/ && ($force = ' >/dev/null 2>&1');
  30.     /^-i/ && ($interactive = 1);
  31.     if (/^-+$/) {
  32.     $startfiles = '- ';
  33.     last;
  34.     }
  35. }
  36.  
  37. chop($pwd = `pwd`);
  38.  
  39. while ($file = shift) {
  40.     if ($file =~ s|^(.*)/||) {
  41.     $dir = $1;
  42.     }
  43.     else {
  44.     $dir = '.';
  45.     }
  46.  
  47.     if ($interactive) {
  48.     print "vanish: remove $dir/$file? ";
  49.     next unless <stdin> =~ /^y/i;
  50.     }
  51.  
  52.     if ($file eq '.deleted') {
  53.     print stderr "To delete .deleted (the trashcan) use the 'empty' command.\n";
  54.     next;
  55.     }
  56.  
  57.     if ($dir ne $olddir) {
  58.     do it() if $olddir;
  59.     $olddir = $dir;
  60.     }
  61.  
  62.     $filelist .= $file; $filelist .= ' ';
  63. }
  64.  
  65. do it() if $olddir;
  66.