Wiki Home

Size For Any File


Namespace: VFP
I had a problem with fopen() and a file (turned out it was too big for fopen() to handle)

So I had to update the routine to detect the file size -- well; this too ended up being a small problem.. Here's the result; it works for anysize file and doesn't require any special DLL's (ie: filer) etc.

FUNCTION GetFileSizeAPI
  LPARAMETERS tcFile
  LOCAL lnHandle AS NUMBER ,;
    lnHiByte AS LONG ,;
    loLoByte AS LONG ,;
    lnSize AS LONG

  DECLARE INTEGER _lopen ;
    IN "kernel32" ;
    AS lOpen ;
    STRING lpPathName, INTEGER nRights

  DECLARE INTEGER _lclose ;
    IN "kernel32" ;
    AS lClose ;
    INTEGER hFile

  DECLARE INTEGER GetFileSize ;
    IN "kernel32" ;
    AS lGetFileSize ;
    INTEGER hFile, INTEGER @lpFileSizeHigh

  lnHandle = lOpen(tcFile, 0)
  IF lnHandle = -1 THEN
    lnSize = -1
  ELSE
    lnHiByte = 0
    lnLoByte = lGetFileSize(lnHandle, @lnHiByte)
    lClose(lnHandle)
    lnSize = INT((lnLoByte + (lnHiByte*2^32)))
  ENDIF

  RETURN lnSize
ENDFUNC


Josh Assing
Is there a problem with using ADIR()? I.e., something like:

   ADIR(aFoo, tcFileName)
   RETURN aFoo[2]

- RushStrong
Another function to get file size:
    *------------------
    func filesize(fname)
    *------------------
    local scomp, nsize
    scomp = set('comp')
    set comp on
    nsize = fsize(fname)
    set comp &scomp
    return nsize
    *------------------

This is faster than using ADIR()
- P L Patodia
Category Code Samples Category UDF
( Topic last updated: 2006.03.21 07:41:24 PM )