ReadFile()

Syntax

Result = ReadFile(#File, Filename$ [, Flags])
Description
Open an existing file for read-only operations.

Parameters

#File The number to identify the file. #PB_Any can be used to auto-generate this number.
Filename$ The filename and path to the file. If the filename does not include a full path, it is interpreted relative to the current directory.
Flags (optional) It can be a combination (using the '| operand) of the following values:
  #PB_File_SharedRead : if the file has been already opened by another process for read operation,
                        this flag is needed to access it (Windows only).
  #PB_File_SharedWrite: if the file has been already opened by another process for write operation,
                        this flag is needed to access it (Windows only).
  #PB_File_NoBuffering: the internal PureBasic file buffering system will be disabled for this file. 
                        FileBuffersSize() can not be used on this file.
combined with one of the following values (the following flags affect the ReadString() and ReadCharacter() behaviour):
  #PB_Ascii  : all read string operation will use ascii if not specified otherwise.
  #PB_UTF8   : all read string operation will use UTF-8 if not specified otherwise (default).
  #PB_Unicode: all read string operation will use Unicode if not specified otherwise.

Return value

Returns nonzero if the file was opened successfully and zero if there was an error. If #PB_Any was used as the #File parameter then the new generated number is returned on success.

Remarks

To open a file for reading and writing, use the OpenFile() function. To create a new and empty file, use the CreateFile() function.

Example


  If ReadFile(0, "Text.txt")   ; if the file could be read, we continue...
    While Eof(0) = 0           ; loop as long the 'end of file' isn't reached
      Debug ReadString(0)      ; display line by line in the debug window
    Wend
    CloseFile(0)               ; close the previously opened file
  Else
    MessageRequester("Information","Couldn't open the file!")
  EndIf

See Also

OpenFile(), CreateFile(), CloseFile()

Supported OS

All

<- ReadDouble() - File Index - ReadFloat() ->