admin 发表于 2023-10-29 21:01:21

检索沙盒内文件夹所有文件名称

input string InpFilter="bucaiea\\*";//需要在MQL4\Files内建立一个bucaiea文件夹
input string comm="A1";//包含名称
int OnInit()
{
   string file_name;
   string int_dir="";
   int    i=1,pos=0,last_pos=-1;
//--- search for the last backslash
   while(!IsStopped())
   {
      pos=StringFind(InpFilter,"\\",pos+1);
      if(pos>=0)
         last_pos=pos;
      else
         break;
   }
//--- 过滤器包含文件夹名称
   if(last_pos>=0)
      int_dir=StringSubstr(InpFilter,0,last_pos+1);
//--- get the search handle in the root of the local folder
   long search_handle=FileFindFirst(InpFilter,file_name);
//--- 检查 FileFindFirst() 是否成功执行
   if(search_handle!=INVALID_HANDLE)
   {
      //--- 检查循环中传递的字符串是否是文件或目录名称
      do
      {
         ResetLastError();
         //--- 如果这是一个文件,函数返回true,如果是目录,它返回错误 ERR_FILE_IS_DIRECTORY
         FileIsExist(int_dir+file_name);
         if(StringFind(file_name,comm)!=-1)
            Print(file_name);
         i++;
      }
      while(FileFindNext(search_handle,file_name));
      //--- 关闭搜索句柄
      FileFindClose(search_handle);
   }
   else
      Print("Files not found!");
   return(INIT_SUCCEEDED);
}

页: [1]
查看完整版本: 检索沙盒内文件夹所有文件名称