Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 2 - File Manager / File Manager Reference
Low-Level HFS Routines / Exchanging the Data in Two Files


You can use the PBExchangeFiles function to exchange the data stored in two files on the same volume.

FUNCTION PBExchangeFiles (paramBlock: HParmBlkPtr; 
                           async: Boolean): OSErr;
A pointer to a basic HFS parameter block.
A Boolean value that specifies asynchronous (TRUE) or synchronous (FALSE) execution.
-->ioCompletionProcPtrA pointer to a completion routine.
<--ioResultOSErrThe result code of the function.
-->ioNamePtrStringPtrA pointer to a pathname.
-->ioVRefNumIntegerA volume specification.
-->ioDestNamePtrStringPtrA pointer to the name of the destination file.
-->ioDestDirIDLongIntThe destination file's parent directory ID.
-->ioSrcDirIDLongIntThe source file's parent directory ID.

The PBExchangeFiles function swaps the data in two files by changing some of the information in the volume catalog and, if the files are open, in the file control blocks. The PBExchangeFiles function uses the file ID parameter block.

You should use PBExchangeFiles to preserve the file ID when updating an existing file, in case the file is being tracked through its file ID.

Typically, you use PBExchangeFiles after creating a new file during a safe save.
You identify the names and parent directory IDs of the two files to be exchanged in
the fields ioNamePtr, ioDestNamePtr, ioSrcDirID, and ioDestDirID. The PBExchangeFiles function changes the fields in the catalog entries that record the location of the data and the modification dates. It swaps both the data forks and the resource forks.

The PBExchangeFiles function works on either open or closed files. If either file is open, PBExchangeFiles updates any file control blocks associated with the file. Exchanging the contents of two files requires essentially the same access privileges as opening both files for writing.

The PBExchangeFiles function does not require that file ID references exist for the files being exchanged.

The trap macro and routine selector for PBExchangeFiles are
Trap macroSelector

noErr0No error
nsvErr-35Volume not found
ioErr-36I/O error
fnfErr-43File not found
fLckdErr-45File is locked
vLckdErr-46Volume is locked or read-only
paramErr-50Function not supported by volume
volOfflinErr-53Volume is offline
wrgVolTypErr-123Not an HFS volume
diffVolErr-1303Files on different volumes
afpAccessDenied-5000User does not have the correct access
afpObjectTypeErr-5025Object is a directory, not a file
afpSameObjectErr-5038Source and destination are the same

Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996