EndOfFile
Flag = EndOfFile(ChannelIndex)
 
Parameters:

    ChannelIndex = Index of the file channel to check
Returns:

    Flag= The end of file status. (1= true, 0 = false)
 

      The EndOfFile function checks the current file pointer position of an open file channel. If the file pointer position hits the end of the file, then the function returns a True(1), it not, the function returns a False(0).



FACTS:


      * If you try and read information beyond the length of a file, you will get a run time error. So EndOFFile, GetFilePos & FileSize can help you ensure this never happens.




Mini Tutorial:


      This example first creates a file of strings. Then in the second part, it reloads this file displaying it's contents. Since the number of lines of text is not stored in the file, the loading while loop continues to load strings until the end of the file has been reached.


  
  
; Create a temp file name
  File$=TempDir$()+"PB_TestFile.txt"
  
; Create a File for writing data to
  WriteFile File$,1
  
; Dump some strings to a the file
  WriteString 1,"Play Basic"
  WriteString 1,"is so easy"
  WriteString 1,"and powerful"
  
; Close this file channel
  CloseFile 1
  
  
  Print "============================"
  Print "Reading File:"+File$
  Print "============================"
  
  
; Get the Size of this file in bytes
  Size=FileSize(File$)
  
; Open a file to READ with READFILE
  ReadFile File$,1
  
; Loop until End OF File is reached
  
  While EndOfFile(1)=0
     Print ReadString$(1)
  EndWhile
  
; Close this file channel
  CloseFile 1
  
  If FileExist(file$) Then DeleteFile file$
  
; Display the screen and wait for key press
  Sync
  WaitKey
  



This example would output.


  
  ============================
  Reading File: C:\Windows\Temp\Pb_TestFile.txt
  ============================
  Play Basic
  is so easy
  And powerful
  


 
Related Info: FilePos | FileSize | GetFilePos | OpenFile | ReadFile :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com