Skip to main content
August 9, 2009
Answered

Format CFDIRECTORY File Sizes

  • August 9, 2009
  • 1 reply
  • 2764 views

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!

    This topic has been closed for replies.
    Correct answer BKBK

    Just calculate them.

    <cfset kb = decimalFormat(size/1024)>
        <cfset mb = decimalFormat(size/(1024*1024))>

    1 reply

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    August 9, 2009

    Just calculate them.

    <cfset kb = decimalFormat(size/1024)>
        <cfset mb = decimalFormat(size/(1024*1024))>

    August 9, 2009

    Thanks, I can do that, than just cfif size output based on filesize in bytes... Thanks.

    Inspiring
    August 9, 2009

    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