Get_Channel_Size
See Also: File I/O Commands, Direct_Input, Direct_Output, Set_Channel_Position
Purpose
To determine the size (in bytes) of a sequential file currently being used for input or output.
Syntax
Get_Channel_Size {channel-num} To {variable}
Argument Explanation
- channel-num: A value between 0 and 9, representing the sequential file I/O channel (Channel Command Component).
- variable: A variable that is set to the size of the sequential file.
What It Does
This command returns the number of bytes or characters (including line formatting characters, such as carriage return and line-feed) of a sequential file. The specified channel must refer to an open sequential file. Zero is returned if Set_Channel_Size acts on a closed channel.
Example
Integer iCount
Integer iSize
String sBuffer
// Create a text file
Direct_Output "hello.txt"
For iCount From 1 To 10
Get_Channel_Size 1 To iSize
Showln "File size of hello.txt is " iSize " bytes."
Writeln "Line: " iCount " - Hello!"
Loop
Get_Channel_Size 1 To iSize
Close_Output
Showln "The size of hello.txt is " iSize
// Error returns 0.
Get_Channel_Size 9 To iSize
Showln "Error channel size is " iSize
// Open file for input.
Direct_Input "hello.txt"
Get_Channel_Size 0 To iSize
Showln "After Direct_Input hello.txt is " iSize " bytes"
Close_Input
Notes
Caution: Unexpected behavior can result from mixing sequential I/O code that uses channels with code that does not, since sequential I/O code that does not use explicit channel numbers will use the default channel or the last channel explicitly specified. We recommend always explicitly using channel numbers.