#!/usr/bin/perl -w# Script to go through the folders / volumes dropped onto it and# delete auxiliary files, dvi files and ps files if a corresponding texfile# exists# Author: Joakim Edsjo# Date: 1999-11-08use Mac::Files;foreach $dirname (@ARGV) {    print "Will now search $dirname for auxiliary files...\n";    ($volume=$dirname) =~ s/^(.*?:).*$/$1/;    $trashdir=FindFolder(hex(substr(MacPerl::MakeFSSpec($volume),1,4)),    kTrashFolderType());#    $trashdir="$volume:Trash";checkdir($dirname);}$size=0 unless defined($size);$nrfiles=0 unless defined($nrfiles);$size=int($size/1024);print "Done.\n";print "I have moved $nrfiles files to the Trash.\n";print "They occupied a total of $size kilobytes.\n";sub checkdir {    my($olddir)=`pwd`;    chomp($olddir);    my($dir)=$_[0];    return if $dir eq "";#    print "Now in directory: '$dir'\n";    return if -s $dir == 0;   # Don't check empty directories    if (chdir "$dir") {                foreach $file (<*>) {	    if ($file =~ /\.tex$/) {	        rmaux($file);	    }	    if (-d $file) {	        checkdir($file);	    }        }    } else {        warn "Can't cd to $dirname: $!\n";    }    chdir("$olddir") || print "Can't cd back to $olddir: $!\n";}sub rmaux {    my $file=$_[0];#    print "Now checking for file $file...\n";    ($auxfile=$file) =~ s/\.tex$/.aux/;    ($logfile=$file) =~ s/\.tex$/.log/;    ($dvifile=$file) =~ s/\.tex$/.dvi/;    ($psfile=$file) =~ s/\.tex$/.ps/;    rmfile($auxfile);    rmfile($logfile);    rmfile($dvifile);    rmfile($psfile);}sub rmfile {    my $file=$_[0];    if (-f $file) {        $size += -s $file;	$nrfiles++;	print "Moving to trash: $file\n";        rename($file,"$trashdir:$file");    }}