• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Format CFDIRECTORY File Sizes

Guest
Aug 08, 2009 Aug 08, 2009

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!

Views

2.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 09, 2009 Aug 09, 2009

Just calculate them.

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

Votes

Translate

Translate
Community Expert ,
Aug 09, 2009 Aug 09, 2009

Copy link to clipboard

Copied

Just calculate them.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2009 Aug 09, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 09, 2009 Aug 09, 2009

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2009 Aug 09, 2009

Copy link to clipboard

Copied

Thanks. Never heard of the site, but I will look there first now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2019 Sep 20, 2019

Copy link to clipboard

Copied

LATEST
I checked out this site, and the function looks perfect for what I need, but - am I supposed to place the source code for the function on my page somewhere in order for the fncFileSize() function to work? (I'm a novice at this.) Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation