Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determining file size
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP1
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01019302
Message ID:
01019312
Views:
26
In addition to what Mike has already provided you, here is a function for returning the size on disk of a file (this code is modified/enhanced version of something I got from somewhere awhile back, I failed to note the source so I am unable to give due credit)
?GetSizeOnDisk(GETFILE(), 1)

************************************
FUNCTION GetSizeOnDisk(tcFileName, tnType)
************************************
*	tnType = 0 for Bytes
*	tnType = 1 for KB
*	tnType = 2 for MB
*	tnType = 3 for GB
************************************
	#DEFINE OF_READ 0 
	#DEFINE OF_SHARE_DENY_NONE 64 
	#DEFINE HFILE_ERROR -1 
	#DEFINE DWORDPLUS 4294967296
	DECLARE INTEGER GetFileSize IN kernel32; 
	    INTEGER   hFile,; 
	    INTEGER @ lpFileSizeHigh 

	DECLARE INTEGER OpenFile IN kernel32; 
	    STRING   lpFileName,; 
	    STRING @ lpReOpenBuff,; 
	    INTEGER  wStyle 

	DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject 

	LOCAL lpReOpenBuff, hFile, lnSizeLo, lnSizeHi, lnReturn

	IF PCOUNT() < 2
		tnType = 1
	ENDIF

	IF TYPE("tcFileName") != "C" OR !FILE(tcFileName)
		lnReturn = 0
	ELSE
		lpReOpenBuff = REPLI (Chr(0), 250) 
		hFile = OpenFile (tcFileName, @lpReOpenBuff, OF_SHARE_DENY_NONE) 
		
		IF hFile <> HFILE_ERROR 
		    lnSizeHi = 0 
		    lnSizeLo = GetFileSize (hFile, @lnSizeHi) 
		    = CloseHandle (hFile) 
		    lnReturn = lnSizeHi * DWORDPLUS + lnSizeLo / 1024^tnType
		ELSE 
		    lnReturn = 0
		ENDIF
	ENDIF
	RETURN lnReturn
ENDFUNC
>How can i programmatically determine the size of a file in KB? I want to pass a file as a parameter and determine the size. If the size is below 500KB do this if greater then do that.
>
>Many Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform