Getting the size of an image file ( or any file for that matter)

I have a app associating image files with jobs. I have sorted getting file date & time, long name and and short name using Clarion, but have not found a method of getting the file size. Are there any suggestions?

! Get image details
!------------------

! File Name (without path)
IF ALC:OriginalFile <> ''
	LX# = LEN(CLIP(ALC:OriginalFile))
    LOOP X# = LX# TO 1 BY -1
    	IF ALC:OriginalFile[X#] = '\'
            BREAK
        END
    END
    IF ALC:OriginalFile[1 : (X#-1)] = LONGPATH(PATH())
    	ALC:StoredImageName = UPPER(ALC:OriginalFile[(X#+1) : LX#])
        DISPLAY(ALC:StoredImageName)
	END
END
! Short 8.3 file name
ALC:OriginalShortName = SHORTPATH(ALC:StoredImageName)
DISPLAY()
! File Extension
LocationOfFullStop# = instring('.',ALC:OriginalFile)
IF (LocationOfFullStop#>0)
    LengthOfFullFileName# = Len(ALC:OriginalFile)
    NumCharactersOfExtension# = LengthOfFullFileName# - LocationOfFullStop# 
    LOC:FileExtn = UPPER(SUB(ALC:OriginalFile, LocationOfFullStop#+1, NumCharactersOfExtension#))
END

ALC:ImageDate   = GETFILEDATE(ALC:OriginalFile)
ALC:ImageTime   = GETFILETIME(ALC:OriginalFile)
ALC:Size		= ALC:OriginalFile{PROP:FileSize}
LOC:ImageSizeMB = (ALC:Size / 1000000)
ALC:StoredImage = ALC:OriginalFile
DISPLAY()

NOTE…Indentation corrected, thank you, Julian: Indentation of the code was lost when pasting into this question!

Have a look at the Directory command, there’s even an example in the C10 help for size info.

1 Like

Agree with Julian - why not just use the directory command and everything at one time.

Either for a single file or for wildcards and do it quickly

If you want to stick to API calls. Check out GetFileSize.

1 Like

Also both Icetips and Capesoft have products to do this. Can’t recall the Icetips but winevent and possibly stringtheory from capesoft

yes winevent:

https://www.capesoft.com/docs/winevent5/WinEvent.htm#ds_GetFileSize

not StringTheory though as to do that would require you to read the whole file into memory.

and the Icetips version:

https://www.icetips.com/manuals/utilities/index.html?getfilesize_core.htm

I’ve used vuFileTools for this (and many other things) for years.

You may want to use the Clarion “Bytes(File), Long” to get the size when the size is not bigger than 2,147,483,647 (max value for a Long).

BYTES Returns number of bytes in FILE, or most recently read.

file The label of a FILE.

The BYTES procedure returns the size of a FILE in bytes or the number of bytes in the last record successfully accessed. Following an OPEN statement, BYTES returns the size of the file. file{PROP:FileSize} is equivalent to BYTES after a file open and will also return the size of the file. After the file has been successfully accessed by GET, REGET, NEXT, PREVIOUS, ADD, or PUT, the BYTES procedure returns the number of bytes accessed in the RECORD. The BYTES procedure may be used to return the number of bytes read in a variable length record.

In SQL tables, if BYTES(file) is used before the file is opened, then it returns the number of rows in the table. If it is used after the file is opened and a successful record retrieval, it returns the number of bytes in the record buffer.

Return Data Type: LONG