3 # $Header: /home/ralph/netatalk/rsync/netatalk/contrib/shell_utils/Attic/apple_mv,v 1.3 2001-10-17 05:21:52 lancel Exp $
6 # Revision 1.3 2001-10-17 05:21:52 lancel
7 # Added error checking against multiple files to one file. Eliminated
8 # depreciated special variable. $ARGV($#ARGV) to $ARGV(-1)
10 # Revision 1.2 2000/08/09 14:12:06 rufustfirefly
11 # /usr/local/bin/perl -> /usr/bin/perl and portability fixes
13 # Revision 1.1 2000/08/09 14:08:06 rufustfirefly
14 # Shell utils from http://www.-genome.wi.mit.edu/ftp/distribution/software/Bass/bass-1.29/apple_util/ (initial import)
16 # Revision 1.2 1996/06/14 18:06:58 lstein
17 # Fixed bugs in the character escaping routines.
19 # Revision 1.2 1996/02/09 18:44:44 will
22 # Revision 1.1 1996/02/09 18:21:35 will
28 Usage: $0 filename1 filename2
29 $0 filename ... directory
30 Do an apple move, moving the resource fork as well
33 @from = @ARGV; pop(@from);
36 if (-f $to && @from > 1) { die $USAGE; }
38 foreach $from (@from) {
40 print STDERR "file $from does not exist\n";
44 if (!-d $to && @from >1) {
45 print STDERR "directory $to does not exist\nCan't move multiple files into one file.\n";
49 $from = escape_bad_chars($from);
50 $to = escape_bad_chars($to);
51 $cmd = "mv $from $to";
52 system $cmd || die "error executing $cmd";
54 ($from_dir, $from_file) = split_dir_file($from);
57 if (!-d "$to/.AppleDouble") {
58 mkdir("$to/.AppleDouble", 0777);
60 $cmd = "mv $from_dir/.AppleDouble/$from_file $to/.AppleDouble/$from_file";
62 ($to_dir, $to_file) = split_dir_file($to);
65 print STDERR "directory $to does not exist\n";
69 if (!-d "$to_dir/.AppleDouble") {
70 mkdir("$to_dir/.AppleDouble", 0777);
72 $cmd = "mv $from_dir/.AppleDouble/$from_file $to_dir/.AppleDouble/$to_file";
75 system $cmd || die "error executing $cmd";
78 sub escape_bad_chars {
80 $file=~s/([^a-zA-Z0-9.-_])/\\$1/;
84 # split a file path into a directory and file name.
88 @path_elems = split(/\//, $path);
90 my $file = pop(@path_elems);
95 $dir = join('/', @path_elems);