Difference between revisions of "Fs.getSize"

From ComputerCraft Wiki
Jump to: navigation, search
(Changing int to number)
(Behaviour change.)
 
Line 5: Line 5:
 
|returns={{Type|number}} size in bytes
 
|returns={{Type|number}} size in bytes
 
|api=fs
 
|api=fs
|desc=Gets the size of a file in bytes. This is not actually the exactly length of the file in bytes; rather, it is the amount that the file contributes towards the computer’s or disk’s storage quota. This is either 512 bytes or the actual length of the file plus the length of its name, whichever is larger.[http://www.computercraft.info/forums2/index.php?/topic/12243-152fsgetsize-returns-unexpected-values/] ComputerCraft will show that any file smaller than 512 bytes as 512 bytes.
+
|desc=Gets the size of a file in bytes. Returns based on the contents of the file - if "file.txt" contains 29 bytes of data, then fs.getSize("file.txt") simply returns the number 29.<br><br>
 +
 
 +
Earlier versions of ComputerCraft returned the filesize ''plus'' the string length of the filename - for example, if "file.txt" contains 1000 bytes of data, then fs.getSize("file.txt") returns 1000 + #"file.txt" = 1008. Furthermore, if the value would be lower than 512, then 512 was returned instead. These behaviours were discarded somewhere between CC 1.53 and CC 1.57.
 
|examples=
 
|examples=
 
{{Example
 
{{Example

Latest revision as of 03:52, 18 August 2015


Grid Redstone.png  Function fs.getSize
Gets the size of a file in bytes. Returns based on the contents of the file - if "file.txt" contains 29 bytes of data, then fs.getSize("file.txt") simply returns the number 29.

Earlier versions of ComputerCraft returned the filesize plus the string length of the filename - for example, if "file.txt" contains 1000 bytes of data, then fs.getSize("file.txt") returns 1000 + #"file.txt" = 1008. Furthermore, if the value would be lower than 512, then 512 was returned instead. These behaviours were discarded somewhere between CC 1.53 and CC 1.57.
Syntax fs.getSize(string path)
Returns number size in bytes
Part of ComputerCraft
API fs

Examples

Grid paper.png  Example
Get the size of the shell from the ROM and print it
Code
print( fs.getSize("/rom/programs/shell") )