How to Get a Macintosh File's Size Without Opening the File (69176)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0b

This article was previously published under Q69176

SUMMARY

There are two methods to get the file size of an Apple Macintosh file through library calls in Microsoft QuickBASIC versions 1.00, 1.00a, and 1.00b for the Apple Macintosh. These library calls are GetFileInfo and HFSDispatch, neither of which requires the file to be open. This article has an example of using each of these calls.

The following information applies to Microsoft QuickBASIC versions 1.00, 1.00a, and 1.00b for Apple Macintosh.

MORE INFORMATION

Both methods, GetFileInfo and HFSDispatch, require using an array as the parameter block record. For more information about the parameter block, query on the following keywords:

ParamBlockRec and HFSDispatch and IOPB

The information returned by both methods is the logical length of both the resource fork and the data fork. These values must be converted into long integers and added together to get the total file length.

GetFileInfo and HFSDispatch are MBLC library resources supplied with QuickBASIC.

Example 1 (below) uses the GetFileInfo Library call. For more detailed information on this call, see page 115 of "Inside Macintosh," Volume 2, by Apple Computer Inc. (published by Addison-Wesley).

Example 1

DIM FileInfo% (40)
filename$ = FILES$(1)
GetFileInfo filename$, FileInfo%(0)
DataForkLength& = FileInfo%(27) * 2 ^ 16 + FileInfo%(28)
RsrcForkLength& = FileInfo%(32) * 2 ^ 16 + FileInfo%(33)
TotalLength& = DataForkLength& + RsrcForkLength&
PRINT "The Length of file "; filename$; " is "; TotalLength&
END
				
Example 2 (below) demonstrates the use of the HFSDispatch method. This method actually calls the routine GetCatInfo, which does not have its own trap address. A pointer to the filename must be inserted into the parameter block record for this method to work correctly. For more information about the GetCatInfo, see page 155 of "Inside Macintosh," Volume 4.

Example 2

DIM IOPB%(60)
filename$ = FILES$(1)
'convert the string to Pascal format:
filename$ = CHR$(LEN(filename$)) + filename$
'Poke the address of the string into the IOPB:
POKEL VARPTR(IOPB%(9)), SADD(filename$)
HFSDispatch 9, IOPB%(0)
DataForkLength& = IOPB%(27) * 2 ^ 16 + IOPB%(28)
RsrcForkLength& = IOPB%(32) * 2 ^ 16 + IOPB%(33)
TotalLength& = DataForkLength& + RsrcForkLength&
PRINT "The Length of file "; filename$; " is "; TotalLength&
END
				

Modification Type:MajorLast Reviewed:10/20/2003
Keywords:KB69176