#!/usr/bin/perl
# 
# $Id: apple_rm.in,v 1.1 2002/01/17 05:59:25 srittau Exp $

$USAGE = <<USAGE;
Usage: $0 filename ...
Do an apple remove, remove the resource fork as well
USAGE

die $USAGE if @ARGV < 1;

foreach $path (@ARGV) {
    if (!-f $path) {
	print STDERR "file $path does not exist\n";
	die $USAGE;
    }

    ($dir, $file) = &split_dir_file($path);

    $cmd = "rm '$path'";
    system $cmd || die "error executing $cmd";
    
    $cmd = "rm '$dir/.AppleDouble/$file'";
    system $cmd || die "error executing $cmd";
}

# split a file path into a directory and file name.
sub split_dir_file {
    my $path = shift;

    @path_elems = split(/\//, $path);

    my $file = pop(@path_elems);
    my $dir;
    if (!@path_elems) {
	$dir = '.';
    } else {
	$dir = join('/', @path_elems);
    }

    $dir, $file;
}
