FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DISK I/O

Get the size of a file without opening it


HGETFILEINFO (the HFS version of GETFILEINFO) is really robust. Here's a slight variation on your routine that will allow to specify the file in a _variety_ of different ways:

'-----------------------------------------
CLEAR LOCAL
LOCAL FN getTheDataForkFileSize%(theFile$, vRefNum%, dirID&)
'-----------------------------------------
  DIM theFileSize&, theKBs%, temp!
  DIM ParamBlock.128
  DIM ioErr%

  ParamBlock.ioCompletion& = _nil
  ParamBlock.ioNamePtr& = @theFile$
  ParamBlock.ioVRefNum% = vRefNum%
  ParamBlock.ioDirID& = dirID&
  ParamBlock.ioFDirIndex& = 0
  ioErr% = FN HGETFILEINFO (@ParamBlock)
  LONG IF ioErr% = 0
    theFileSize& = ParamBlock.ioFlPyLen&
  END IF

  temp! = theFileSize&/1024
  theKBs% = INT(temp!)
END FN = theKBs%
'-------------------------------------------

Here's how to call this routine:
* If you have a complete path name for the file, then specify it in theFile$. The vRefNum% and dirID& parameters are ignored in this case.

* If you have a file name and a working directory ref. number, then pass them in theFile$ and vRefNum%, and pass 0 in dirID&.

* If you have a file name, a volume reference number and a directory ID number (as in the components of an FSSpec record), then pass them in theFile$, vRefNum% and dirID&, respectively.

If what you're really interested in using is an FSSpec record, then here's a very minor modification that will work:

'-----------------------------------------
DIM RECORD fsSpecRec
  DIM fsVRefNum%
  DIM fsParID&
  DIM 63 fsName$
DIM END RECORD .fsSpecRec
'-----------------------------------------
CLEAR LOCAL
LOCAL FN getTheDataForkFileSize%(fsSpecPtr&)
'Call as follows:
' theKBs% = FN getTheDataForkFileSize%(@myFSSpec)
'where "@myFSSpec" is the pointer to a 70-byte FSSpec record.
'-----------------------------------------
  DIM theFileSize&, theKBs%, temp!
  DIM ParamBlock.128
  DIM ioErr%

  ParamBlock.ioCompletion& = _nil
  ParamBlock.ioNamePtr& = @fsSpecPtr&.fsName$
  ParamBlock.ioVRefNum% = fsSpecPtr&.fsVRefNum%
  ParamBlock.ioDirID& = fsSpecPtr&.fsParID&
  ParamBlock.ioFDirIndex& = 0
  ioErr% = FN HGETFILEINFO (@ParamBlock)
  LONG IF ioErr% = 0
    theFileSize& = ParamBlock.ioFlPyLen&
  END IF

  temp! = theFileSize&/1024
  theKBs% = INT(temp!)
END FN = theKBs%

Rick