uh-huh
have a nice day...
//+------------------------------------------------------------------+ //| CheckFileSeek.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| https://www.metaquotes.net/ru/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "https://www.metaquotes.net/ru/" //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- int ExtHandle=FileOpenHistory(Symbol()+Period()+".hst", FILE_BIN|FILE_READ|FILE_WRITE); // open read/write //FileSeek(ExtHandle,0,SEEK_END); // go to end of file int i_time,byteswritten;//=FileWriteInteger(ExtHandle,i_time,LONG_VALUE); // write integer to end of file ok //Print("bytes written=",byteswritten," err=",GetLastError()); // byteswritten=4 err=0 bool resFileSeek=FileSeek(ExtHandle,-4,SEEK_END); // go to value just written if (!resFileSeek) Print("FileSeek() is failed"); int x=FileReadInteger(ExtHandle,LONG_VALUE); // read value just written Print("x written=",x," err=",GetLastError()); // if (ExtHandle>0) FileClose(ExtHandle); //---- return(0); } //+------------------------------------------------------------------+
Result:
2007.10.23 13:47:43 CheckFileSeek EURUSD,H1: uninit reason 0
2007.10.23 13:47:43 CheckFileSeek EURUSD,H1: x written=1081757696 err=0
2007.10.23 13:47:43 CheckFileSeek EURUSD,H1: loaded successfully
2007.10.23 13:47:28 Compiling 'CheckFileSeek'
phy was right. Read documentation about FileFlush function
Notes: The FileFlush() function must be called between operations of file reading and writing in the file.
phy was right. Read documentation about FileFlush function
Notes: The FileFlush() function must be called between operations of file reading and writing in the file.
I have a similar problem with reading one and writing to another file. I tried FileFlush() after, but it did not correct the problem.
string delimiter = ","; // comma as delimiter
int handleA = FileOpen(readFile, FILE_CSV|FILE_READ,delimiter); // reading from file
//FileFlush(handleA); // this did not change anything
int handleB = FileOpen(writeFile, FILE_CSV|FILE_WRITE,delimiter); // writing to file, also tried FILE_CSV|FILE_READ|FILE_WRITE as suggested somewhere
....
while(!FileIsEnding(handleA)){
FileWriteString(handleB,FileReadString(handleA,1),1);
}
I am trying to copy readFile to writeFile, but all it creates is an EMPTY (writeFile) file. ReadFile contains 4 values in unformatted fields of CSV file, delimeter is ok (checked with notepad). Iget a "Incompatible access to a file" error wtih this code. I think reading is ok (tested with print command in while loop)), but writing seems to cause this problem.
Tried also do the same thing with int res = ShellExecuteA(0,0,"ren readFile writeFile,0,0,SW_SHOW); //for WinXP OS, but could not find a working solution with a proper command.
Can someone see the problem?
nickel
"also tried FILE_CSV|FILE_READ|FILE_WRITE as suggested somewhere"
That would be the correct opening method to append an existing file.
FileReadString(handleA,1)
Why a 1?
FileWriteString(handleB,......
FileWriteString is for writing to Binary file, not CSV
I suggest you review the documentation and samples for File operations.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I was working with FileHistory and opened file with FILE_READ|FILE_WRITE combination.
It appears that at first writing to the file file gets extended, but as soon as FileRead... is made extending file becomes impossible, that is when writing to the end of the file 0 bytes gets written and last error is zero too. In other words:
I don't know is it MQ4 bug or just the way windows files work?