top of page

How big is my database, exactly?



GetFileSize custom function from FileMaker Pro Miami Developer Automation USA

Bits and Bytes

Been nurturing a FileMaker database for a few years now? Is it fast approaching "big data" proportions? Concerned about exactly how big your file(s) have become? With a maximum size of 8 Terabytes per file, it's quite possible to accumulate a large amount of data in a FileMaker application, especially on a multiple file solution.

A little while ago, we decided to tackle the accuracy and "legibilty" of FileMaker's native "Get (FileSize)" function to see if we could make it more readable, usable, and understandable by mere mortals. As we see it, there are two main issues with this function: the first is it reports file size in number of bytes (which means nothing to most people), the second is there is disagreement about how many bytes make up one megabyte (MB).

You see, depending on how you count (Metric or Binary), a megabyte is either 1,000,000 bytes or 1,024,000 bytes. So, in addition to being a really long number, those bytes reported by FileMaker can mean different things to different people.

Introducing "GetFileSize"

After a cursory internet search for a custom function to address this, we set about writing our own "File Size" custom function, not knowing others had already addressed this under a different name. As it turns out, we think we ended up producing a more flexible and thorough custom function that allows you to customize the results and get more "mileage" out of it. We called our custom function "GetFileSize", and it lets you convert any "raw" byte size number into the appropriate magnitude figure in human readable format, using the standard of your preference.

For example, you can ask it to use the metric or binary standard in any of three ways (short: {"M", or "B"}; long: {"metric" or "binary"}; and numeric: {"1000" or "1024"} ). You can also ask it to round the results to any decimal place. Lastly, you can choose to append a unit label suffix (i.e. megabytes, gigabytes, terabytes, etc.) either in abbreviated or "long" format.

You can get the code by copying the text below or follow either of these two code repository links:

Let ( [

RawBytes = Int ( Bytes ) ;

Unit = Case (

IsEmpty ( UOM ) ; 1024 ;

UOM = "metric" or UOM = "M"; 1000 ;

UOM = "binary" or UOM = "B" ; 1024 ;

UOM = "1000" or UOM = 1024 ; UOM ;

//defaultResult

1024

) ; //end Case

Kilobyte = Unit ;

Megabyte = ( Kilobyte ^ 2 ) ;

Gigabyte = ( Kilobyte ^ 3 ) ;

Terabyte = ( Kilobyte ^ 4 ) ;

Petabyte = ( Kilobyte ^ 5 ) ;

Exabyte = ( Kilobyte ^ 6 ) ;

Zettabyte = ( Kilobyte ^ 7 ) ;

Yottabyte = ( Kilobyte ^ 8 ) ;

Decimals = If ( IsEmpty ( precision ) ;

0 ;

Abs ( Int ( precision ) )

) ; //end If

Magnitude = Floor ( Ln ( RawBytes ) / Ln ( Unit ) ) ;

Magnitude = Min ( Magnitude ; 8 ) ; // don't exceed known magnitude units

Magnitude = Unit ^ Magnitude ;

Label = Case (

IsEmpty ( Format ) ; "" ;

Format = "long" or Format = "L" ;

Case (

RawBytes ≥ Yottabyte ; "Yottabyte" ;

RawBytes ≥ Zettabyte ; "Zettabyte" ;

RawBytes ≥ Exabyte ; "Exabyte" ;

RawBytes ≥ Petabyte ; "Petabyte" ;

RawBytes ≥ Terabyte ; "Terabyte" ;

RawBytes ≥ Gigabyte ; "Gigabyte" ;

RawBytes ≥ Megabyte ; "Megabyte" ;

RawBytes ≥ Kilobyte ; "Kilobyte" ;

//defaultResult

"Byte"

) ; //end Case

Format = "short" or Format = "S" ;

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

"B"

) ; //end Case

//defaultResult

""

) ; //end Case

Size = Round ( RawBytes/Magnitude ; Decimals )

] ;

//calculation

Size & " " & If ( Left ( Format ; 1 ) = "L" and Size ≠ 1 ; Label & "s" ; Label )

) //end Let

0 comments
bottom of page