FindFirstFile/FindNextFile

 
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
 

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

 

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);
   }  
//+------------------------------------------------------------------+
 

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

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

See sample script:

Dear Rosh,

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

Regards,

 
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.
Reason: