[comp.sys.apple] copying files of any type

hartkopf@tramp.Colorado.EDU (HARTKOPF JEFFREY M) (06/15/89)

What is a good method for copying a file (of any type) from one
disk to another, using Apple IIGS toobox routines (if possible)?
Is there just a simple routine that will do it for me?  I'd appreciate
any suggestions, and if examples are included I'd prefer them in
Pascal or C.  Thanks a lot.


Jeff Hartkopf

Internet:
hartkopf@tramp.Colorado.EDU

dlyons@Apple.COM (David Lyons) (06/16/89)

In article <9425@boulder.Colorado.EDU> hartkopf@tramp.Colorado.EDU (HARTKOPF JEFFREY M) writes:
>What is a good method for copying a file (of any type) from one
>disk to another, using Apple IIGS toobox routines (if possible)?
>Is there just a simple routine that will do it for me?  I'd appreciate
>any suggestions, and if examples are included I'd prefer them in
>Pascal or C.  Thanks a lot.
>
>Jeff Hartkopf

The toolbox doesn't provide what you want.  You need to make GS/OS calls like
OPEN, CREATE, READ, WRITE, and CLOSE.  You need the GS/OS Reference manusls
from APDA, and you should get updated System Disk 5.0 documentation from APDA
as soon as it's available.  Oh, I forgot GET_FILE_INFO and SET_FILE_INFO.

Note that some files are "extended" (2 forks), and you need to copy both forks.

Your application may need to read the file in chunks if there isn't enough
memory available to read a whole fork at a time.  Use NewHandle to allocate
your memory, of course.  Deciding *how much* memory to allocate is a very
interesting question.  You could call MaxBlock and only allocate something
less than that, but there will typically be *more* memory than that available,
maybe even in one chunk, since there will be purgable memory blocks lying around.

The best answer is probably to *try* allocating as much as you need to do the
copy in one chunk, and keep cutting down the size until the NewHandle succeeds.
(You could keep cutting it in half, keep chopping off a fixed amount, or try
dividing the needed size by larger and larger numbers.  These have different
implications; I'd go for the last one, I think.)

 --Dave Lyons, Apple Computer, Inc.          |   DAL Systems
   AppleLink--Apple Edition: DAVE.LYONS      |   P.O. Box 875
   AppleLink--Personal Edition: Dave Lyons   |   Cupertino, CA 95015-0875
   GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
   Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons

   My opinions are my own, not Apple's.