List all files in the Files-folder with FindFileFirst() possible?

 

Hello,

is it possible to list all files of the directory TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL5\\Files\\" ?

I tried to use the script from Metaquotes which is found at the description of FindFileFirst() but that didn't work. I always received "Files not found" although I placed some files there.

Or is it not possible with FindFileFirst()?

Thank you!

 

https://www.mql5.com/en/docs/files/filefindfirst

if you are not able to list  "TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL5\\Files\" could be due sandbox or the path is not specific.

Firslty, Does Folder  exist? , close previously open Folder  then Find List .

Documentation on MQL5: File Functions / FileFindFirst
Documentation on MQL5: File Functions / FileFindFirst
  • www.mql5.com
FileFindFirst - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Mary A Thompson #:

https://www.mql5.com/en/docs/files/filefindfirst

if you are not able to list  "TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL5\\Files\" could be due sandbox or the path is not specific.

Firslty, Does Folder  exist? , close previously open Folder  then Find List .

Unfortunately that doesn’t help me. I already used the code on the website and it didn’t work  

The path I use is a „built-in“ folder which is always there after the installation of MT5.

 
Marbo #:Unfortunately that doesn’t help me. I already used the code on the website and it didn’t work. The path I use is a „built-in“ folder which is always there after the installation of MT5.

It does work! You must be using it incorrectly, but since you did not show your code, we are unable to specify what it is you are doing wrong.

Also remember that the "Files" folder under the Strategy Tester is in a different location to when using it on a live chart. Maybe that is what is causing your issue.

 
Fernando Carreiro #:

It does work! You must be using it incorrectly, but since you did not show your code, we are unable to specify what it is you are doing wrong.

Also remember that the "Files" folder under the Strategy Tester is in a different location to when using it on a live chart. Maybe that is what is causing your issue.

Got it!! I use "*" as the InpFilter and now it works. I am pretty confused about the folder structure in MT5 but it works! :)

 

Lets say you have "Screens" subdirectory in your Files directory and want to list all files from "Screens" subdirectory.


void OnStart()
  {
//---
        string folder = "Screens", file_name; int i = 0;
        long search_handle = FileFindFirst(folder + "\\*",file_name);
//---
        do{if(FileIsExist(folder + "//" + file_name)) Print(++i,": ",file_name);}
        while(FileFindNext(search_handle,file_name));
//---
        FileFindClose(search_handle);
        PrintFormat("%d files in \"%s\" directory.",i,folder);
  }
//+------------------------------------------------------------------+