How to read several external .csv files

 
I'd like to use Script for reading information from external .csv files. 
If I know how many files exist and the name of the files it is easy with the code below. 

...but how to modify the file for smooth working 
- if I don't know how many files exist
- if I don't know the name of the files 
?

many thanks for help

void OnStart()
{
      int handle; string str;  string str1; 

  
      handle=FileOpen("AAA.csv", FILE_CSV|FILE_READ);  
      if(handle>0)
      {
       str=FileReadString(handle); 
       str1=FileReadString(handle);     
       printf("handle:" +handle + ";  str:"+str + ";  str1:" + str1);
      }

      handle=FileOpen("BBB.csv", FILE_CSV|FILE_READ);
      if(handle>0)
      {
       str=FileReadString(handle); 
       str1=FileReadString(handle); 
       printf("handle:" +handle + ";  str:"+str + ";  str1:" + str1);
      }
      


 
KertLopper:
 
...but how to modify the file for smooth working 
- if I don't know how many files exist
- if I don't know the name of the files 

Just use FileFindFirst(), FileFindNext() and FileFindClose()

 
Petr Nosek:

Just use FileFindFirst(), FileFindNext() and FileFindClose()

Thank you but I've rather thought about some loop. 

Does anyone have an idea how to build loops for this ?

 
KertLopper:

Thank you but I've rather thought about some loop. 

Does anyone have an idea how to build loops for this ?

Of course you have to use these functions in a loop. See the documentation https://www.mql5.com/en/docs/files/filefindfirst
Documentation on MQL5: File Functions / FileFindFirst
Documentation on MQL5: File Functions / FileFindFirst
  • www.mql5.com
[in]  Search filter. A subdirectory (or sequence of nested subdirectories) relative to the \Files directory, in which files should be searched for, can be specified in the filter. [out]  The returned parameter, where, in case of success, the name of the first found file or subdirectory is placed. Only the file name is returned (including the...
 

Petr Nosek:
Of course you have to use these functions in a loop. See the documentation https://www.mql5.com/en/docs/files/filefindfirst


Thank You!

All works fine.

Full code below (if somebody will need it for ourself)

void OnStart()
{
   string file_name;
   string int_dir="";
   int    i=1;
   int handle; string str;  string str1; 
   
   long search_handle=FileFindFirst("*",file_name);
   if(search_handle!=INVALID_HANDLE)
     {
      do
        {
         FileIsExist(int_dir+file_name);
      handle=FileOpen(file_name , FILE_CSV|FILE_READ);  
      if(handle>0)
      {
       str=FileReadString(handle); 
       str1=FileReadString(handle);     
       printf("handle:" +handle + ";  str:"+str + ";  str1:" + str1);
      }
         i++;
        }
      while(FileFindNext(search_handle,file_name));
          {
          FileFindClose(search_handle);
          }
     }            
}


Reason: