A folder is not deleted if it contains unclosed files - page 3

 
Реter 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 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

FileOpen - Файловые операции - Справочник MQL4
FileOpen - Файловые операции - Справочник MQL4
  • docs.mql4.com
FileOpen - Файловые операции - Справочник MQL4
 
Rashid Umarov:

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...

 
Реter Konow:

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.

 
A100:

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.

 
fxsaber:

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.

Thanks. Glad I'm not the only one facing this problem. I need to solve this problem (can't finish usingfile navigator without it). I have written to servicedeck. But I am writing here too, just in case. It turned out not in vain).
 
Реter Konow:

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

 
Реter Konow:

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

2017.08.28 17:36:18.525 Demo_FolderDelete EURUSD.e,H4: Не удалось удалить папку nonempty. Код ошибки=5025
2017.08.28 17:36:16.985 Demo_FolderDelete EURUSD.e,H4: Не удалось очистить папку nonempty. Код ошибки=5026

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...

2017.08.28 17:50:45.328 Demo_FolderDelete (CADJPY,H4)   Не удалось очистить папку nonempty. Код ошибки=5025
2017.08.28 17:50:47.958 Demo_FolderDelete (CADJPY,H4)   Не удалось удалить папку nonempty. Код ошибки=5024
 
The servicedeck replied. They said that the file has to be closed after creation. But I close it and the problem remains... Alas...(
 
Alexey Viktorov:

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?

 
Реter Konow:
But I close it and the problem remains... Alas...(
And try FILE_COMMON everywhere
Reason: