file_size
result = file_size(path)
Input: path · Output: result
What it is
Reports a file's size without opening it. path (string) is the file to stat.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = file_size(path) | path stringnot documented yet | result number | Returns a number: the size in bytes on disk. Worth asking before you read something you did not write. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
f = fopen("log.txt", "w")
write_line(f, "run started")
write_line(f, "value = " + str(42))
close(f)
print(file_size("log.txt")) # 23 -- "run started\n" + "value = 42\n"
output
23
from file-io
f = fopen("flags.bin", "wb")
write_bit(f, 1)
write_bit(f, 0)
write_bit(f, 1)
write_bit(f, 1)
close(f) # only 4 bits written -- flushed as one padded byte
g = fopen("flags.bin", "rb")
b0 = read_bit(g)
b1 = read_bit(g)
b2 = read_bit(g)
b3 = read_bit(g)
close(g)
print("{b0}{b1}{b2}{b3}") # 1011
print(file_size("flags.bin")) # 1 -- one byte on disk for 4 bits
output
1011 1
from file-io
f = fopen("temps.bin", "wb")
write_double(f, 20.5)
write_double(f, 21.0)
write_double(f, 19.8)
close(f)
print(file_size("temps.bin")) # 24 -- 3 doubles, 8 bytes each
g = fopen("temps.bin", "rb")
vals = read_values(g, "f64", 3)
close(g)
print(vals) # [20.5, 21, 19.8]
whole = read_array("temps.bin", type="f64")
print(whole) # [20.5, 21, 19.8]
output
24 [20.5, 21, 19.8] [20.5, 21, 19.8]
from file-io