Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager / Resource Manager Reference
Resource Manager Routines / Creating an Empty Resource Fork


You can use the FSpCreateResFile procedure to create an empty resource fork using a file system specification (FSSpec) record.

PROCEDURE FSpCreateResFile (spec: FSSpec; 
                            creator, fileType: OSType;
                            scriptTag: ScriptCode);
A file system specification record that indicates the name and location of the file whose resource fork is to be created.
The signature of the application creating the file.
The file type of the new file.
The script code of the script system in which the Finder and standard file dialog boxes display the file's name.
The FSpCreateResFile procedure creates an empty resource fork for a file with the specified type, creator, and script code in the location and with the name designated by the spec parameter. (An empty resource fork contains no resource data but does include a resource map.)

This procedure is available only in System 7 and later versions of system software. If FSpCreateResFile is not available to your application, you can use HCreateResFile or CreateResFile.

The spec parameter is a file system specification record, which is the standard format in System 7 and later versions for identifying a file or directory. The file system specification record for files and directories is defined by the FSSpec data type.

TYPE FSSpec = {file system specification}
      vRefNum: Integer;    {volume reference number}
      parID:   LongInt;    {directory ID of parent directory}
      name:    Str63;      {filename or directory name}
Certain File Manager routines--those that open a file's data fork--also take a file system specification record as a parameter. You can use the same FSSpec record in Resource Manager routines that create or open the file's resource fork.

The creator parameter of FSpCreateResFile contains the signature of the application that creates the file. Whenever your application creates a document, it assigns a creator and a file type to that document. Typically your application sets its signature as the document's creator.

The fileType parameter indicates the type of file. You can set the file type to a type especially defined for your application or one of the existing general types, such as 'TEXT' for text (a stream of ASCII characters), or 'pref' for a preferences file.

The file type should be as descriptive of the file's data format as possible. You should not use 'TEXT' as a file type unless the document contains plain ASCII characters.
The value of the scriptTag parameter is the script code of the script system in which the Finder and the Standard File Package dialog boxes display the name of the file. For example, to specify the Roman script system, specify the constant smRoman in the scriptTag parameter.

If the file specified by the file system specification record doesn't already exist (that is, if it has neither a data fork nor a resource fork), the FSpCreateResFile procedure creates a resource file--that is, a resource fork, including a resource map. In this case the file has a zero-length data fork. The FSpCreateResFile procedure also sets the creator, type, and script code fields of the file's catalog information record to the specified values.

If the file specified by the file system specification record already exists and includes a resource fork with a resource map, FSpCreateResFile does nothing. If the data fork of the file specified by the file system specification record already exists but the file has a zero-length resource fork, FSpCreateResFile creates an empty resource fork and resource map for the file; it also changes the creator, type, and script code fields of the catalog information record of the file to the specified values.

If your application uses Standard File Package routines, note that the StandardPutFile procedure returns a standard file reply record that contains a file system specification record in the sfFile field.

Before you can work with the newly created file's resource fork, you must use the FSpOpenResFile function to open it.

The FSpCreateResFile procedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.

noErr0No error
dirFulErr-33Directory full
dskFulErr-34Disk full
nsvErr-35No such volume
ioErr-36I/O error
bdNamErr-37Bad filename or volume name (perhaps zero length)
tmfoErr-42Too many files open
wPrErr-44Disk is write-protected
fLckdErr-45File is locked
To check for errors, call the ResError function as described on page 1-47. For information about using the Gestalt function to determine whether the FSpCreateResFile procedure is available, see "Using the Resource Manager," beginning on page 1-11. For a discussion of the use of the FSpCreateResFile procedure, see "Creating and Opening a Resource Fork" beginning on page 1-19. For a description of the FSpOpenResFile function, see page 1-54. For information about the StandardPutFile procedure and standard file reply records, see Inside Macintosh: Files. For more information on creators and file types, see the chapter "Finder Interface" in Inside Macintosh: Macintosh Toolbox Essentials.

The trap macro and routine selector for the FSpCreateResFile procedure are
Trap macroSelector

Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996