[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Copying Files



On Wed, May 20, 1998 at 11:29:25AM +0200, Carl Johan Berglund wrote:
} At 03.13 +0200 98-05-20, Paul J. Schinder wrote:
} >use File::Copy;
} >
} >copy($file1,$file2);
} >
} >I can't tell for sure just by looking, and I'm not running MacOS at
} >the moment, but I think this will do cross volume copies.  It also deals
} >with the resource fork of the file properly.
} 
} I'd like to copy files without copying the resource forks. Can File::Copy
} do that?

See below, but that you usually do the plain old fashioned way:

#!perl

open(IN,"<$file1") or die;
open(OUT,">$file2") or die;
my $buffer, $bin, $bout;
while(defined($bin = sysread(IN,$buffer,2048))) {
   $bout = syswrite(OUT,$buffer,$bin);
   if ($bout != $bin) {
	#do something, but this should never happen
	}
}

since MacPerl ordinarily reads and writes only the data fork.  File::Copy has
a more robust implementation of this.

If you're into kludges, you can probably also get File::Copy to copy only the
data fork by setting $^O to something like $^O = "unix", since File::Copy
defaults to Unix behavior.  Matthias has modified it to do the right thing
under MacPerl, and the modification examines $^O.  I've never done this,
though.

The resource fork only can be copied by using POSIX::{open, read,
write} and Fcntl::O_RSRC(), a flag that Matthias added that tells
POSIX::open that you want to open the resource fork of the file.

} 
} 
} ___Carl_Johan_Berglund_________________________
}    Adverb Information
}    carl.johan.berglund@adverb.se
}    http://www.adverb.se/
} 
} 

---
Paul Schinder
schinder@pobox.com

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch