Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

GetFileSize ( Bytes ; Precision ; UOM ; Format )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.3  (27 votes)
  Discuss this Custom Function

Julio Toledo, Automation USA, LLC
http://www.automationusa.net

Converts bytes into a labeled file size, appending

Sample Input:
GetFileSize ( Get ( FileSize ) ; 2 ; "" ; "long" )
GetFileSize ( Get ( FileSize ) ; "" ; "" ; "s" )
GetFileSize ( Get ( FileSize ) ; 2 ; "metric" ; "long" )
Sample Output:
"1.35 Gigabytes" - where Get ( FileSize ) = 1447866368 bytes
"411 MB" - where Get ( FileSize ) = 430714880 bytes
"1.45 Gigabytes" - where Get ( FileSize ) = 1447866368 bytes


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

PURPOSE:
• Rounds bytes to the nearest order of magnitude ( up to the Yottabyte level ) at the requested precision [defaults to 0 decimal places] .
• Optionally appends "short-form" ( "MB" ) or "long-form" ( "Megabytes" ) unit label [defaults to <null>].
• Provides option to use metric ( 1000 bytes ) or binary (1024 bytes ) unit of measure [defaults to binary].

EXAMPLES:
Input: GetFileSize ( Get ( FileSize ) ; 2 ; "" ; "long" )
Output: "1.35 Gigabytes" - where Get ( FileSize ) = 1447866368 bytes

Input: GetFileSize ( Get ( FileSize ) ; 2 ; "metric" ; "long" )
Output: "1.45 Gigabytes" - where Get ( FileSize ) = 1447866368 bytes

Input: GetFileSize ( Get ( FileSize ) ; "" ; "" ; "s" )
Output: "411 MB" - where Get ( FileSize ) = 430714880 bytes

HISTORY:
2015-10-23 Julio Toledo - Automation USA ( http://www.automationusa.net ). Function originally employed hardcoded binary values and forcibly appended "short form" unit label.
2015-10-31 Julio Toledo - Added "UOM" parameter to optionally use metric standard ( 1000 bytes ).
2015-10-31 Julio Toledo - Added "Format" parameter to optionally append unit label.
2015-10-31 Julio Toledo - Optimized case statement for "Label" variable as per contributions by "Bruce, from Redmond WA". ( Thank you Bruce ).
2015-10-31 Julio Toledo - Optimized "Size" evaluation based on "Magnitude" logarithmic code from Jeremy Bante's "ByteSize" custom function ( http://www.briandunning.com/cf/1447 , https://github.com/jbante/ )

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 6 comments

Thanks Bruce,

I take your point, but the reason for the "and <" is not to determine label name, but rather to determine what value "RawBytes" needs to be divided by.

Julio, Miami, FL
October 30, 2015 10:11am

Sorry that makes no sense.

Bruce, Redmond WA
October 30, 2015 10:09pm

But to (perhaps) clarify; my comment was only about that particular section. The complete calc would be like this:

/*
GetFileSize ( bytes ; precision )
http://www.briandunning.com/cf/1820
2015-10-23 Julio Toledo - Automation USA ( http://www.automationusa.net )
Converts bytes into a labeled file size, appending "short-form" unit symbol up to the Yottabyte level. Can be easily modified to include "long-form" unit name.
*/

Let ( [

RawBytes = Int ( Bytes ) ;

Kilobyte = 1024 ;
Megabyte = 1048576 ;
Gigabyte = 1073741824 ;
Terabyte = 1099511627776 ;
Petabyte = 1125899906842624 ;
Exabyte = 1152921504606846976 ;
Zettabyte = 1180591620717411303424 ;
Yottabyte = 1208925819614629174706176 ;

Decimals = If ( IsEmpty ( precision ) ;
2 ;
Abs ( Int ( precision ) )
) ; //end If


Label = Case (
RawBytes ≥ Yottabyte ; "YB" ;
RawBytes ≥ Zettabyte ; "ZB" ;
RawBytes ≥ Exabyte ; "EB" ;
RawBytes ≥ Petabyte ; "PB" ;
RawBytes ≥ Terabyte ; "TB" ;
RawBytes ≥ Gigabyte ; "GB" ;
RawBytes ≥ Megabyte ; "MB" ;
RawBytes ≥ Kilobyte ; "KB" ;
//defaultResult
"Bytes"

) ; //end Case

Size = Case (

Label = "KB" ; Round ( RawBytes/Kilobyte ; Decimals ) ;
Label = "MB" ; Round ( RawBytes/Megabyte ; Decimals ) ;
Label = "GB" ; Round ( RawBytes/Gigabyte ; Decimals ) ;
Label = "TB" ; Round ( RawBytes/Terabyte ; Decimals ) ;
Label = "PB" ; Round ( RawBytes/Petabyte ; Decimals ) ;
Label = "EB" ; Round ( RawBytes/Exabyte ; Decimals ) ;
Label

Bruce, Redmond WA
October 30, 2015 10:21pm

Somehow the paste got chopped but hopefully you can figure out that the end of the calc should remain like the bottom section of the existing calc.

Bruce, Redmond WA
October 30, 2015 10:25pm

Thanks Bruce,

based on your feedback, I completely revisited and expanded upon the code.

It turns out there already was a similar function written by Jeremy Bante back in 2012 which did not turn up during my original search, so I ended up writing this one instead.

In this last revision, I took your input as well as some choice lines of code from Jeremy's function and made this one much better than before, I think.

Thanks again,

-Julio

Julio, Miami, FL
October 31, 2015 11:55am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 7 + 6 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions