Consultor Eletrônico



Kbase P6116: How can I get the size of any given file ?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   1/29/2003
Status: Unverified

GOAL:

How can I get the size of any given file ?

FACT(s) (Environment):

Progress 8.3x

FACT(s) (Environment):

Windows 32 Intel

CAUSE:

In Progress version 9.0x the FILE-INFO handle was updated to return the file size of a given file, however in previous versions the FILE-SIZE attribute was missing and howsoever there was not a straight way to obtain this data from a 4GL regular statement.

FIX:

This code instruct how to obtain the size of a given file:

/*
filesize.p
*/
DEF VAR fName as CHAR.
DEF VAR fInfo as MEMPTR.
DEF VAR fSize as INTEGER.
DEF VAR res as INTEGER.

ASSIGN SET-SIZE(fInfo) = 318
fName = "c:\autoexec.bat". /* The name of the file */

RUN FindFirstFileA (fName,fInfo, OUTPUT res).
IF (res <> -1 ) THEN ASSIGN fsize = GET-LONG(fInfo,33).

MESSAGE fSize VIEW-AS ALERT-BOX. /*here we only show the file size */

/* Call to the OS Kernel to get the file info memory structure */
PROCEDURE FindFirstFileA EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER extFileName as CHAR.
DEFINE INPUT PARAMETER extFileStructure as MEMPTR.
DEFINE RETURN PARAMETER extResult as LONG.
END.