File.getSize
$file.getSize($units='B', $options={}) -> number
Description
Get the file size in the given units (default: 'B'
= bytes).
See Number.fromBytesTo for supported units.
We recommend the following decimal units for file sizes: kB
, MB
, GB
.
TipTo avoid unit conversion bugs, append the unit name to the variable name. (e.g.
$fileSizeMb
)$dataFile = file'files:/data.txt' $sizeBytes = $dataFile.getSize() //= Ex: 5234000 $sizeMb = $dataFile.getSize('MB') //= Ex: 5.234
Options
Option | Value | Description |
---|---|---|
ifExists |
true/false | If the file does not exist, return 0 instead of triggering an error. |
$missingFile.getSize('MB', -ifExists)