Cecil
19+ years progress programming and still learning.
Hi,
Today I need needed a function to return the a give file size into a human readable format. Now I've written a few variation of this code over many years, but this time I looked at some Python code and I converted it into the ABL. Because of it's simplicity I thought I would share it. It could be useful for anybody else who needed formatted value of a file size.
Today I need needed a function to return the a give file size into a human readable format. Now I've written a few variation of this code over many years, but this time I looked at some Python code and I converted it into the ABL. Because of it's simplicity I thought I would share it. It could be useful for anybody else who needed formatted value of a file size.
Code:
FUNCTION fileSizer RETURNS CHARACTER (INPUT pdeFileSize AS DECIMAL):
DEFINE VARIABLE chUnitSize AS CHARACTER NO-UNDO EXTENT 6 INITIAL ['bytes','KB','MB','GB','TB','PB'].
DEFINE VARIABLE inLoop AS INTEGER NO-UNDO.
DO inLoop = 1 TO EXTENT(chUnitSize):
IF pdeFileSize LT 1024 THEN
RETURN SUBSTITUTE('&1 &2',
ROUND(pdeFileSize,2),
chUnitSize[inLoop]
).
pdeFileSize= (pdeFileSize / 1024).
END.
END FUNCTION .
Last edited: