46 lines
827 B
Perl
46 lines
827 B
Perl
#!/usr/bin/perl
|
|
|
|
# $Header: /home/cvs/386BSD/ports/lang/perl/eg/van/empty,v 1.1.1.1 1993/08/23 21:29:45 nate Exp $
|
|
|
|
# This script empties a trashcan.
|
|
|
|
$recursive = shift if $ARGV[0] eq '-r';
|
|
|
|
@ARGV = '.' if $#ARGV < 0;
|
|
|
|
chop($pwd = `pwd`);
|
|
|
|
dir: foreach $dir (@ARGV) {
|
|
unless (chdir $dir) {
|
|
print stderr "Can't find directory $dir: $!\n";
|
|
next dir;
|
|
}
|
|
if ($recursive) {
|
|
do cmd('find . -name .deleted -exec /bin/rm -rf {} ;');
|
|
}
|
|
else {
|
|
if (-d '.deleted') {
|
|
do cmd('rm -rf .deleted');
|
|
}
|
|
else {
|
|
if ($dir eq '.' && $pwd =~ m|/\.deleted$|) {
|
|
chdir '..';
|
|
do cmd('rm -rf .deleted');
|
|
}
|
|
else {
|
|
print stderr "No trashcan found in directory $dir\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
continue {
|
|
chdir $pwd;
|
|
}
|
|
|
|
# force direct execution with no shell
|
|
|
|
sub cmd {
|
|
system split(' ',join(' ',@_));
|
|
}
|
|
|