路路发智能交易研发中心

 找回密码
 立即注册
查看: 5758|回复: 0

MT4智能交易编程教程-FileIsExist函数

    [复制链接]

管理员

MT4软件工程师

Rank: 9Rank: 9Rank: 9

积分
6521
帖子
2771
主题
2761
QQ
发表于 2014-3-27 10:08:09 | 显示全部楼层 |阅读模式
MT4智能交易编程教程-FileIsExist函数
检测文件是否存在。
bool  FileIsExist(
   const string  file_name,       // 文件名
   int           common_flag=0    // 搜索区
   );

参量
file_name
[in]  被检测的文件名
common_flag=0
[in] 标记 决定文件位置,如果common_flag = FILE_COMMON,文件为所有客户端放置共享文件夹。否则,文件放置在本地文件夹中。
返回值
如果指定文件存在返回真值。
注释
Checked file can turn out to be a subdirectory. in this case, FileIsExist() function will return false, while error 5018 will be logged in _LastError variable - "This is a directory, not a file" (see example for FileFindFirst function).
  出于安全考虑,工作文件必须严格由MQL5语言管理。使用MQL5实    施文件操作的文件意味着,不能在文件沙箱外。
如果common_flag = FILE_COMMON,函数为所有客户端在共享文件中寻找文件,否则函数在本地文件夹中寻找文件 (MQL5 \ Files or MQL5 \ Tester \ Files 检测状态下)。
示例:
//--- show the window of input parameters when launching the script
#property script_show_inputs
//--- date for old files
input datetime InpFilesDate=D'2013.01.01 00:00';
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string   file_name;      // variable for storing file names
   string   filter="*.txt"; // filter for searching the files
   datetime create_date;    // file creation date
   string   files[];        // list of file names
   int      def_size=25;    // array size by default
   int      size=0;         // number of files
//--- allocate memory for the array
   ArrayResize(files,def_size);
//--- receive the search handle in the local folder's root
   long search_handle=FileFindFirst(filter,file_name);
//--- check if FileFindFirst() executed successfully
   if(search_handle!=INVALID_HANDLE)
     {
      //--- searching files in the loop
      do
        {
         files[size]=file_name;
         //--- increase the array size
         size++;
         if(size==def_size)
           {
            def_size+=25;
            ArrayResize(files,def_size);
           }
         //--- reset the error value
         ResetLastError();
         //--- receive the file creation date
         create_date=(datetime)FileGetInteger(file_name,FILE_CREATE_DATE,false);
         //--- check if the file is old
         if(create_date<InpFilesDate)
           {
            PrintFormat("%s file deleted!",file_name);
            //--- delete the old file
            FileDelete(file_name);
           }
        }
      while(FileFindNext(search_handle,file_name));
      //--- close the search handle
      FileFindClose(search_handle);
     }
   else
     {
      Print("Files not found!");
      return;
     }
//--- check what files have remained
   PrintFormat("Results:");
   for(int i=0;i<size;i++)
     {
      if(FileIsExist(files))
         PrintFormat("%s file exists!",files);
      else
         PrintFormat("%s file deleted!",files);
     }
  }



外汇智能交易,成就财富梦想!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


MT4编程培训|EA定制开发|QQ在线咨询|路路发智能交易研发中心

GMT+8, 2024-4-20 11:51 , Processed in 0.168812 second(s), 26 queries .

© 2009-2022 520EA.com EA668.com

快速回复 返回顶部 返回列表