FileSize ( file$ )
Parameters
| file$ - path and name of the file |
Description
|
Returns the size of a file, in bytes. Returns 0 if the file does not exist or cannot be read - and of course a real file can legitimately be 0 bytes, so use FileType when you need to know whether it exists at all. Knowing the size up front is most useful just before reading a whole file into memory: create a bank of exactly FileSize bytes and pull the lot in with ReadBytes. See also: FileType, ReadBytes, CreateBank. |
Example
; FileSize Example ; ---------------- ; Write a few typed values to a demo file file=WriteFile("demo_filesize.dat") WriteInt file,12345 WriteFloat file,3.5 WriteString file,"Robo" CloseFile file ; FileSize returns the length of a file in bytes Print "demo_filesize.dat is "+FileSize("demo_filesize.dat")+" bytes" Print "(4 int + 4 float + 4 string length + 4 characters = 16)" ; Clean up the demo file DeleteFile "demo_filesize.dat" Print "" Print "Deleted demo_filesize.dat" Print "" Print "Press any key to close the example" WaitKey End
Index