3 # $Id: apple_mv.in,v 1.1 2002-01-17 05:59:25 srittau Exp $
6 Usage: $0 filename1 filename2
7 $0 filename ... directory
8 Do an apple move, moving the resource fork as well
11 @from = @ARGV; pop(@from);
14 if (-f $to && @from > 1) { die $USAGE; }
16 foreach $from (@from) {
18 print STDERR "file $from does not exist\n";
22 if (!-d $to && @from >1) {
23 print STDERR "directory $to does not exist\nCan't move multiple files into one file.\n";
27 $from = escape_bad_chars($from);
28 $to = escape_bad_chars($to);
29 $cmd = "mv $from $to";
30 system $cmd || die "error executing $cmd";
32 ($from_dir, $from_file) = split_dir_file($from);
35 if (!-d "$to/.AppleDouble") {
36 mkdir("$to/.AppleDouble", 0777);
38 $cmd = "mv $from_dir/.AppleDouble/$from_file $to/.AppleDouble/$from_file";
40 ($to_dir, $to_file) = split_dir_file($to);
43 print STDERR "directory $to does not exist\n";
47 if (!-d "$to_dir/.AppleDouble") {
48 mkdir("$to_dir/.AppleDouble", 0777);
50 $cmd = "mv $from_dir/.AppleDouble/$from_file $to_dir/.AppleDouble/$to_file";
53 system $cmd || die "error executing $cmd";
56 sub escape_bad_chars {
58 $file=~s/([^a-zA-Z0-9.-_])/\\$1/;
62 # split a file path into a directory and file name.
66 @path_elems = split(/\//, $path);
68 my $file = pop(@path_elems);
73 $dir = join('/', @path_elems);