Hello friend,
Does your code really do what you say it does?
Hello friend,
Does your code really do what you say it does?
No. It does not do what I want it to do?
MQL5 Reference :
FileReadString ... When reading from a csv-file, the string length isn't required also, the string will be read from the current position till the nearest delimiter or till the text string end character.
This means the for loop only reads the first 5 words of the first line. But it looks like you wanted to read the whole file, line by line.
If you drop FILE_CSV from the file flags it should work much better.
MQL5 Reference :
FileReadString ... When reading from a csv-file, the string length isn't required also, the string will be read from the current position till the nearest delimiter or till the text string end character.
This means the for loop only reads the first 5 words of the first line. But it looks like you wanted to read the whole file, line by line.
If you drop FILE_CSV from the file flags it should work much better.
MQL5 Reference :
FileReadString ... When reading from a csv-file, the string length isn't required also, the string will be read from the current position till the nearest delimiter or till the text string end character.
This means the for loop only reads the first 5 words of the first line. But it looks like you wanted to read the whole file, line by line.
If you drop FILE_CSV from the file flags it should work much better.
But I am doing both reading and writing using one FileOpen command, and I understand that opening with FILE_CSV while writing removes delimiters (;) from the file even if specified in the code. And like you said, reading with FILE_CSV reads one cell at a time and not one record row at a time. So how do I go about it?
string Tra[], TraRec; //int AdjustHandle=FileOpen("AdjustFile.txt",FILE_READ|FILE_WRITE|FILE_CSV|FILE_TXT|FILE_ANSI); int AdjustHandle=FileOpen("AdjustFile.txt",FILE_READ|FILE_TXT|FILE_ANSI); //int TransferAdjustHandle=FileOpen("TransferAdjustFile.txt",FILE_READ|FILE_WRITE|FILE_CSV|FILE_TXT); int TransferAdjustHandle=FileOpen("TransferAdjustFile.txt",FILE_WRITE|FILE_CSV|FILE_TXT); for (int ID = 0; ID <= 4; ID++) { TraRec = FileReadString(AdjustHandle);StringSplit(TraRec,';', Tra); FileWrite(TransferAdjustHandle, Tra[0] ,Tra[1], Tra[2], Tra[3], Tra[4]); } FileClose(AdjustHandle); FileClose(TransferAdjustHandle);Just a guess. Only change are the file flags. Give it a try.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I want to copy from "AdjustFile.txt" to "TransferAdjustFile.txt" one record at a time
The content of the "AdjustFile.txt" is as follows:
But I am getting the following content for "TransferAdjustFile.txt"
I used the following codes:
What could be the problem? Thanks in advance.