跳至内容

FileIsEnding

FileIsEnding

定义文件在读取过程中的结束位置。

bool  FileIsEnding(
   int  file_handle      // File handle
   );

参数

file_handle

[in] 由 FileOpen() 返回的文件描述符。

返回值

如果文件指针在读取或移动过程中到达了文件的末尾,该函数返回 true。

注意

为了定义文件的结束位置,函数尝试从文件中读取下一个字符串。如果字符串不存在,函数返回 true;否则返回 false。

示例:

//--- show the window of input parameters when launching the script
#property script_show_inputs
//--- input parameters
input string InpFileName="file.txt";    // file name
input string InpDirectoryName="Data";   // directory name
input int    InpEncodingType=FILE_ANSI; // ANSI=32 or UNICODE=64
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- print the path to the file we are going to use
   PrintFormat("Working %s\\Files\\ folder",TerminalInfoString(TERMINAL_DATA_PATH));
//--- reset the error value
   ResetLastError();
//--- open the file for reading (if the file does not exist, the error will occur)
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_TXT|InpEncodingType);
   if(file_handle!=INVALID_HANDLE)
     {
      //--- print the file contents
      while(!FileIsEnding(file_handle))
         Print(FileReadString(file_handle));
      //--- close the file
      FileClose(file_handle);
     }
   else
      PrintFormat("Error, code = %d",GetLastError());
  }
最后更新于