
Copy link to clipboard
Copied
Hi. I output the file sizes from a <cfdirectory> list that I use, and it shows in bytes. Is there a way to make it so that if it is over 1024 bytes it shows 1KB (or 1.2, whatever the appropriate size is) and in MB if over 1024 KB, and so on... The files will get large, and I don't want to be outputting extremely large file sizes.
Thanks!
1 Correct answer
Just calculate them.
<cfset kb = decimalFormat(size/1024)>
<cfset mb = decimalFormat(size/(1024*1024))>
Copy link to clipboard
Copied
Just calculate them.
<cfset kb = decimalFormat(size/1024)>
<cfset mb = decimalFormat(size/(1024*1024))>

Copy link to clipboard
Copied
Thanks, I can do that, than just cfif size output based on filesize in bytes... Thanks.
Copy link to clipboard
Copied
BKBK already answered your question. But in future you may also want to check cflib.org first for these types of questions. They have a function a function for that 😉
http://www.cflib.org/udf/fncFileSize

Copy link to clipboard
Copied
Thanks. Never heard of the site, but I will look there first now.
Copy link to clipboard
Copied

