![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
As far as I know, if no changes were made to the file using file functions (e.g. FileWrite()), there is no need to close it. The FileOpen() function simply creates a new file and this operation does not require closing the file (the documentation for this function, too, does not say that the file needs to be closed after creation).
Oy-lee! Storyteller https://docs.mql4.com/ru/files/fileopen
//--- the correct way to work in the "file sandbox"
ResetLastError();
filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_CSV);
if(filehandle!=INVALID_HANDLE)
{
FileWrite(filehandle,TimeCurrent(),Symbol(),EnumToString(ENUM_TIMEFRAMES(_Period));
FileClose(filehandle);
Print("FileOpen OK");
}
elsePri
Oy-lee! Storyteller https://docs.mql4.com/ru/files/fileopen
What is the contradiction with what I said?
I said, -
Retag Konow:
As far as I know, if no changes were made to the file using file functions (e.g. FileWrite()), there is no need to close it. The FileOpen() function just creates a new file and this operation does not require closing the file (the documentation for this function, too, does not say that the file needs to be closed after creation).
But in your example the FileWrite() function is used immediately after the file is created. And then you use FileClose(filehandle);
Also, in the above script code I added an explicit closure, but that didn't solve anything...
Exactly like this. When I try to delete a folder that already contains subfolders and files, I delete the files first. Only the subfolders remain. I try to clean them using FolderClean() and then call FolderDelete(). However, the result is that those subfolders that were empty are well deleted, but if there were more subfolders inside the subfolders they are not deleted. After that, I try to remove the folders from the file navigator in MetaEditor manually, but the terminal does not remove them and pops up this window:
I click on "Continue", agree to the changes, but the folder is still not erased. After completely closing and reopening the terminal, the folders that should have been erased either disappear on their own or not, but you can erase them immediately and manually without the above window.
Such strange things...
I've seen this kind of thing many times. I figured out that at some point the Files folder with all its subfolders and files gets read-only attribute. Deselecting this flag manually doesn't help. But restarting terminal always helps. Couldn't get it to play (didn't try), so didn't report it to SD.
The error (5022) only occurs if you set FILE_COMMON
It clears the folder but does not delete it
This flag does not need to be set, otherwise the file will be searched in the shared folder, and the error says that the directory name is wrong.
File path
"\\MQL4\\Files";
does not require this flag to be set. So everything is correct.
I've seen this kind of thing happen more than once. I found out that at some point Files folder with all subfolders and files gets read-only attribute. Deselecting this flag manually doesn't help. But restarting terminal always helps. Couldn't get it to play (didn't try), so didn't report it to SD.
This flag does not need to be set, otherwise the file will be searched in the public folder and the error says that the directory name is wrong.
Both with and without FILE_COMMON - it works (originally when checking I forgot to put this flag in the last if). With FILE_COMMON it was implied that it is present in all operations
This flag does not need to be set, otherwise the file will be searched in the public folder, and the error says that the directory name is wrong.
The path to the file
does not require this flag to be set. So everything is correct.
This is strange. I noticed the MQL4 folder paths and recompiled the code into .ex4 and strangely enough, the code worked without errors. I removed the closing of the file and got
Then without corrections I ran it on mt5 and strangely enough the mention of MQL4 folder was ignored. The folder and the file have been created in the MQL5 folder. From here everything is the same as in MT4. An unclosed file is not deleted...
This is all strange. I noticed the MQL4 folder paths and recompiled the code into .ex4 and strangely enough, the code worked without errors. Removed the file closure and got
Then without corrections I ran it on mt5 and strangely enough the mention of MQL4 folder was ignored. The folder and the file have been created in MQL5 folder. From here everything is the same as in MT4. An unclosed file is not deleted...
I mean, you made an Expert Advisor out of a script and tried to run it?
But I close it and the problem remains... Alas...(