help needed to get variables from filename

 

Hi

I have been experimenting with some code to obtain some variables from a filename.

Here is an example: 60_EURUSDFXF_12345678.sell

So with an EA I would like to extract the info to be used:

int time ="", period="";
string sym = "", ext = "";

fn = period + "_" + sym + "_" + time + ext;

fn = FileOpen(fn,FILE_CSV|FILE_READ,";");

Print(period); //return Period() value from filename
Print(sym); // return Symbol() value from filename
Print(time); // return iTime() value from filename
Print(ext); // return extension name from filename

This is what I have got to at the moment but all values return 0, do I need to use SubString("") ?

If so how can I do this please?

Thanks

Antony

 
Print(period); //return Period() value from filename      no it doesn't
Print(sym); // return Symbol() value from filename        no it doesn't
Print(time); // return iTime() value from filename        no it doesn't
Print(ext); // return extension name from filename        no it doesn't
   

you have to use one of the FileRead's functions... first

 

Oh, just noticed that you referring to fileName and not the content

use StringSplit and convert the result using right StringTo... for instance StringToTime Etc.

Reason: