Skip to main content
Aug 9, 2009 3:56 AM UTC
Answered

Format CFDIRECTORY File Sizes

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 is closed to new replies. Start a new post to keep the conversation going.
    BKBK
    BKBKCorrect answer
    Community Expert
    Aug 9, 2009 5:06 PM UTC

    Just calculate them.

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

    5 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    Aug 9, 2009 5:06 PM UTC

    Just calculate them.

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

    Translate
    Aug 9, 2009 6:25 PM UTC

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

    Translate
    Inspiring
    Aug 9, 2009 6:46 PM UTC

    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

    Translate