– Common Function Library Project


Last updated February 3, 2009


Kyle Morgan

Version: 3 | Requires: CF5 | Library: FileSysLib

After using a variety of different methods to generate file sizes of files being uploaded to a server for public downloads, frustration lead to writing of this tag. It will calculate in bytes, kilobytes, and megabytes, and return an accurate number to help plan/keep track of the size of files. To use the function, just use #fncFileSize(Number)# and it will return an accurate calculation. If you provide a variable that is not numerical, it will return 'Error'.

Return Values:
Returns a string.




Name Description Required
number Size in bytes of the file. Yes

Full UDF Source:

 * Will take a number returned from a File.Filesize, calculate the number in terms of Bytes/Kilobytes/Megabytes and return the result.
 * v2 by Haikal Saadh
 * v3 by Michael Smith, cleaned up and added Gigabytes
 * @param number 	 Size in bytes of the file. (Required)
 * @return Returns a string. 
 * @author Kyle Morgan ( 
 * @version 3, February 3, 2009 
function fncFileSize(size) {
	if (size lt 1024) return "#size# b";
	if (size lt 1024^2) return "#round(size / 1024)# Kb";
	if (size lt 1024^3) return "#decimalFormat(size/1024^2)# Mb";
	return "#decimalFormat(size/1024^3)# Gb";
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson