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

Format CFDIRECTORY File Sizes

Guest
Aug 08, 2009 Aug 08, 2009

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!

2.6K
Translate
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))>

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

Just calculate them.

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

Translate
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

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

Translate
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

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
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

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

Translate
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
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!
Translate
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