ADC Home > Reference Library > Technical Q&As > Legacy Documents > Mac OS 9 & Earlier >
Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.
Current information on this Reference Library topic can be found here:
|
Q How can I completely delete the resource fork associated with a file
(so the file has absolutely no resource fork associated with it)? A To delete a file fork without deleting the file, you need to open the file fork with the File Manager, set the fork's EOF to zero, and then close the file. The following code does this: pascal OSErr HDeleteFork(short vRefNum, long dirID, ConstStr255Param fileName, Boolean isResourceFork); /* [[paragraph]] Delete a fork of a file without deleting the file. The HDeleteFork function deletes a file's data or resource fork. The isResourceFork parameter specifies the fork to delete. vRefNum input: Volume specification. dirID input: Directory ID. fileName input: The name of the file. isResourceFork input: The file fork to delete. If true, the resource fork is deleted; if false, the data fork is deleted. */ pascal OSErr HDeleteFork(short vRefNum, long dirID, ConstStr255Param fileName, Boolean isResourceFork) { OSErr result; short refNum; if ( isResourceFork ) { result = HOpenRF(vRefNum, dirID, fileName, fsRdWrPerm, &refNum); } else { result = HOpenDF(vRefNum, dirID, fileName, fsRdWrPerm, &refNum); if ( result == paramErr ) { /* HOpenDF isn't supported under System 6, so retry with HOpen */ result = HOpen(vRefNum, dirID, fileName, fsRdWrPerm, &refNum); } } if ( result == noErr ) { result = SetEOF(refNum, 0); (void) FSClose(refNum); } return ( result ); } On HFS volumes, setting a file fork's EOF to zero releases all allocation blocks associated with the file. However, some foreign file systems add information to the volume's catalog when a resource fork is added and don't remove that data when you set the EOF to zero. For example, on ProDOS volumes, opening a resource fork for a file changes the file to an "extended" file, which can only be opened with GS/OS on an Apple IIgs (extended ProDOS files cannot be opened by ProDOS 8 on an Apple II). With file systems that exhibit this behavior, the only way to remove all traces of the file's resource fork is to copy the file's data fork and then delete the original file. The MoreFiles sample code on the Tool Chest edition of the Developer CD includes a routine called CopyFork that copies only the data fork. Updated: 1-June-95 |
|