Download MetaTrader 5

FindFirstFile/FindNextFile

To add comments, please log in or register
Lance Wynn
26
Lance Wynn  
I have been trying to use the FindFirstFile, and FindNextFile, but I cannot seem to get them to work. Does anyone have any sample code to show how to obtain a list of files in a directory?

Lance
Daniel F
348
Daniel F  

yeah, that's what I am looking for, too.

Could you please tell us how to do it? Do we have to write a DLL for it?


Daniel

Rashid Umarov
Admin
12608
Rashid Umarov  

See sample script:

//+------------------------------------------------------------------+
//|                                                CheckFindFile.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
 
#property show_inputs
 
#import "kernel32.dll"
int  FindFirstFileA(string path, int& answer[]);
bool FindNextFileA(int handle, int& answer[]);
bool FindClose(int handle);
#import
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int LP[82];
   
   int handle = FindFirstFileA(TerminalPath() + "\experts\*.mq4",LP);
   //Print("error = ", GetLastError());
   Print(bufferToString(LP));
   ArrayInitialize(LP,0);
   while (FindNextFileA(handle,LP))
      {
      Print(bufferToString(LP));
      ArrayInitialize(LP,0);
      }
 
   if (handle>0) FindClose(handle);
   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
string bufferToString(int buffer[])
   {
   string text="";
   
   int pos = 11;
   for (int i=0; i<65; i++)
      {
      pos++;
      int curr = buffer[pos];
      text = text + CharToStr(curr & 0x000000FF)
         +CharToStr(curr >> 8 & 0x000000FF)
         +CharToStr(curr >> 16 & 0x000000FF)
         +CharToStr(curr >> 24 & 0x000000FF);
      }
   return (text);
   }  
//+------------------------------------------------------------------+
Daniel F
348
Daniel F  

thanks so much, Rosh. Your support is amazing, we're glad to have you.

pgk
3
pgk  
After hours of googleing u finally made my day. Thank u
RFB
127
RFB  
You haven't probably searched why when dos had been created were (skipped 7) used every next 8-th bits ;).
och
486
och  
Rosh:

See sample script:

Dear Rosh,

This code does not works anymore on build 610, any idea?

Regards,

Alain Verleyen
Moderator
33281
Alain Verleyen  
och:

Dear Rosh,

This code does not works anymore on build 610, any idea?

Regards,


Strings in mql4 are know using Unicode instead of ANSI, you have to use WinApi function accordingly.
To add comments, please log in or register