Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GetFileAttributesEx
Message
From
10/03/2006 15:10:32
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01102961
Message ID:
01103250
Views:
12
Sergey,

I've tried using the GetFileSize api and it is not giving the results that I expect. Here are snippets of my code, mostly from samples on your website :-)

This is the code in the prg based class:
#DEFINE MAX_INT 0x100000000
PROTECTED pnFileSize
LOCAL ppFileInformation

ppFileInformation = REPLICATE(CHR(0), 53)

IF GetFileAttributesEx (tcFile, 0, @ppFileInformation) != 0 
	tcFileSizeHi = SUBSTR( ppFileInformation, 29, 4 ) 
	tcFileSizeLo = SUBSTR( ppFileInformation, 33, 4 ) 

    	threadFreeLo = THIS.buf2dword ( tcFileSizeLo )
        threadFreeHi = THIS.buf2dword ( tcFileSizeHi )
	This.pnFileSize  = THIS.getLargeInt( threadFreeLo, threadFreeHi ) 
ENDIF

FUNCTION getFileSize()
	RETURN This.pnFileSize
ENDFUNC

PROTECTED FUNCTION getLargeInt (tnlowValue, tnhighValue ) 
        RETURN MAX_INT * tnhighValue + tnlowValue 
ENDFUNC
I call this class by:
loFileAttributes = CreateObject ("fileAttributes", tcFile ) 
? "File Size = ", loFileAttributes.getFileSize()
The PRG Class Returns: "File Size = 11417657818"

Here is the VCX based class code:
SET CLASSLIB TO ..\classes\mathconversions.vcx
This.oMath = CREATEOBJECT( 'mathconversions' )

LOCAL lcFileSizeHi, lcFileSizeLo
lcFileInformation = REPLICATE(CHR(0), WIN32_FILE_ATTRIBUTE_DATA_LEN )    && NULL terminated buffer that emulates the WIN32_FILE_ATTRIBUTE_DATA Structure

IF GetFileAttributesEx( tcFile, 0, @lcFileInformation ) != 0 

	lcFileSizeHi = SUBSTR( lcFileInformation, 29, 4 ) 
	lcFileSizeLo = SUBSTR( lcFileInformation, 33, 4 ) 

	lnFileSizeLo = This.oMath.buf2dword( lcFileSizeLo )
        lnFileSizeHi = This.oMath.buf2dword( lcFileSizeHi )
        lnFileSize = THIS.oMath.getLargeInt( lnFileSizeHi, lnFileSizeLo )
	This.pnFileSize = THIS.oMath.getLargeInt( lnFileSizeHi, lnFileSizeLo )

ENDIF

getFilesize method:
RETURN This.pnFileSize
I call this class by:
SET CLASSLIB TO fileattributes
oFile = CREATEOBJECT( 'getfileattributes', 'filename here' )

?oFile.getFilesize()
The VCX Class Returns: 1.2144978777809600E+19

So any ideas of what the difference is?

Thanks!
Bruce Crane
Software Engineer
Regulus Integrated Solutions, LLC - Napa
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform