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

 
Rashid Umarov:

I remember your "I have all the moves written down" in the OOP vs procedural programming thread. In this thread I was just convinced that you cannot be trusted.

There is no evidence and no details - there is no need to write to the servicedesk.


My problem with deleting folders is still unresolved. The script works, but I haven't found the cause of my problem yet.


There are all sorts of possibilities. It may or may not be my fault. I am always ready to provide the information needed to solve the problem.


My feedback to servicedek is by no means a complaint.

 
Rashid Umarov:

I remember your "I have all the moves written down" in the OOP vs procedural programming thread. In this thread I was just convinced that you can't be trusted.

I don't know what moves you're talking about, and why you think I can't be trusted. I may have given a reason to do so, but I don't remember exactly where or when.

In any case, thank you for your frank statement of your attitude to me. It's better to know than not to know.

 

I hope you really understand, you have done a great job of Harmful Advice - how not to write to Service Desk

 
Rashid Umarov:

I hope you really get it, you've done a great job of Harmful Advice - how not to write to Service Desk


Alas, I didn't get it. I tried to be as clear and specific as possible in my message. I gave details, gave a gif-file, commented code of the script. So what exactly have I done wrong?

 

You really can't read the help and change the code correctly? How can you then demand a different attitude? Here is the code from the help, with the additions highlighted in yellow

//+------------------------------------------------------------------+
//|                                                Test_FileOpen.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- неправильный способ открытия файла
   string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
   string filename=terminal_data_path+"\\MQL5\\Files\\"+"fractals.csv";
   int filehandle=FileOpen(filename,FILE_WRITE|FILE_CSV);
   if(filehandle<0)
     {
      Print("Неудачная попытка открыть файл по абсолютному пути");
      Print("Код ошибки ",GetLastError());
     }
//--- правильный способ работы в "файловой песочнице"
   ResetLastError();
   filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_CSV);
   if(filehandle!=INVALID_HANDLE)
     {
      FileWrite(filehandle,TimeCurrent(),Symbol(),EnumToString(_Period));
      FileClose(filehandle);
      Print("FileOpen OK");
     }
   else Print("Операция FileOpen неудачна, ошибка ",GetLastError());

//--- еще один пример с созданием вложенной директории в MQL5\Files\
   string subfolder="Research";
   filehandle=FileOpen(subfolder+"\\fractals.txt",FILE_WRITE|FILE_CSV);
   if(filehandle!=INVALID_HANDLE)
     {
      FileWrite(filehandle,TimeCurrent(),Symbol(),EnumToString(_Period));
      FileClose(filehandle);
      Print("Файл должен быть создан в папке "+terminal_data_path+"\\"+subfolder);
     }
   else Print("Операция FileOpen неудачна, ошибка ",GetLastError());
//---
   Print("Очищаем папку \\MQL5\\",subfolder);
   FolderClean(subfolder,1);

   Print("Удаляем папку \\MQL5\\",subfolder);
   if(!FolderDelete(subfolder,1))
      PrintFormat("Ошибка! Не удалось удалить папку  \\MQL5\\",subfolder);
  }
//+------------------------------------------------------------------+
 
Rashid Umarov:

Are you really unable to read the help and change the code correctly? How can you ask for a different attitude? Here is the code from the help, with the additions in yellow

If the attitude to my person depends on whether I have made a mistake in the code, then I'm afraid something is wrong here...))

I still, don't really understand your claims.

I've posted my altered code more than once on the forum. My only mistake was that after adding the explicit file closure, I forgot to re-save the script and therefore didn't see that it solved the problem in the script I changed. However, in any case, the documentation doesn't explicitly say that you have to close the files after creation.

Past that, as I said before, my problem with erasing folders (note not files) still remained. The folders no longer have files in them, but the FolderClean function erases them.

The cause is not yet clear.

So, maybe I went to Service Desk for a reason after all.

Thank you for taking such a long time to consider my problem)).

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

I've seen this kind of thing happen a number of times. 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.

Joining. I've had previously extremely rare crashes since early 2014 that generated an OS "32 Sharing violation" error in 9 attempts to create a file in this folder, going in 16 millisecond increments in a row. I couldn't figure out what was wrong. I blamed it on the "radical upgrade of the file handling functions" that was going on in MQ at the time. Can't reproduce either, just by coincidence there was this glitch at 20:12:42. Immediately, a few seconds passed, went to a file in that folder, managed to edit it correctly and save it. Failure not caught.

Before that crash was occurring once or twice a month for 5 years, since February 2014 it must be every week, I don't count how many times. Although the number of simultaneously running terminals decreased from 40-50 to 35.

 
Vladimir:

Accompanying. I've had a previously extremely rare failure since early 2014 that generated an OS "32 Sharing violation" error in 9 attempts to create a file in this folder, going in 16 millisecond increments in a row. I couldn't figure out what was wrong. I blamed it on the "radical upgrade of the file handling functions" that was going on in MQ at the time. Can't reproduce either, just by coincidence there was such a glitch just now, at 20:12:42. Immediately, a few seconds passed, went to a file in that folder, managed to edit it correctly and save it. The glitch is not caught.

Before that, for 5 years this error appeared once or twice a month, since February 2014 it has been invariably every week, I couldn't count how many times. Although the number of simultaneously running terminals decreased from 40-50 to 35.

All my files are being erased even without closing them explicitly. Erased because I didn't create them and they were previously inside the Files folder.

The thing is, in order to erase a file, we need its handle. However, if we didn't create the file, but only placed it in the Files folder, we can't get its handle, and therefore we can't close it with FileClose().

At the same time, we can still copy or erase it. However, the folder cannot be deleted after that either programmatically or manually. Manually only after restarting the terminal.

I'll try to reproduce the problem more clearly later, with clear examples.

 
Реter Konow:

I get all the files erased even without closing them explicitly. Erased because I didn't create them and they were previously inside the Files folder.

The point is that in order to erase a file, we need its handle. However, if we didn't create this file, but only put it into Files folder, we can't get its handle, and therefore we can't close it with FileClose().

At the same time, we can still copy or erase it. However, the folder cannot be deleted after that either programmatically or manually. Manually only after restarting the terminal.

I'll try to reproduce the problem more clearly later, with clear examples.

This is probably the crux of the problem.

When renaming a folder in the custom file navigator, I can't use FolderRename() because it doesn't exist.

Instead, I copy all files and folders to a new folder, with a custom name, and delete the original original files and folders from the original folder (which I rename). As a result, I first erase all files from the original folder (after copying them to the new folder) and then use FolderClean() to try to remove the remaining folder hierarchy in the original folder, which is already empty. This is where the error occurs. Some folders are erased, but one or two remain, just like the source folder. Afterwards I try to erase it manually and it fails. Only restarting the terminal helps.

 
Реter Konow:

This is probably the crux of the problem.

When renaming a folder in the custom file navigator, I can't use FolderRename() because it doesn't exist.

Instead, I copy all the files and folders into a new folder, with a custom name, and delete the original original files and folders from the original folder (which I rename). As a result, I first erase all files in the original folder (after copying them into the new folder) and then use FolderClean() to try to remove the remaining folder hierarchy in the original folder, which is already empty. This is where the error occurs. Some folders are erased, but one or two remain, just like the source folder. Afterwards I try to erase it manually and it fails. Only restarting the terminal helps.


Please continue - as long as you write in the fascinating genre of "fiction". Hopefully by about page 40 you'll have moved on to the "technical literature" genre.

Reason: