FileClose - The process cannot access the file because it is being used by another process. 5004

To add comments, please log in or register
samjesse
645
samjesse  

The process cannot access the file because it is being used by another process.

This is the message I get from Window 10 when I try to open a file by double clicking its name in Windows Explorer after this mql5 code opened and closed the same file.

Since the code needs to run on many charts, it works the first time but failed to open the file the second time due to the the file process issue above.

Any suggestion as to what I need to do?

Thanks

void newsMarksFromFile(string fileName){
  int fH = FileOpen(fileName, FILE_READ | FILE_ANSI | FILE_COMMON, 0);
  if(fH!=INVALID_HANDLE){
    Print("file opened");  // Prints the first time the EA is attached
    while(!FileIsEnding(fH)){
     // DO STUFF HERE...
    }
  } else {
   Print("Error opening file: "+ GetLastError());  // Prints 5004
  }
  FileClose(fileName);
}
Drazen Penic
2766
Drazen Penic  
samjesse:

The process cannot access the file because it is being used by another process.

This is the message I get from Window 10 when I try to open a file by double clicking its name in Windows Explorer after this mql5 code opened and closed the same file.

Since the code needs to run on many charts, it works the first time but failed to open the file the second time due to the the file process issue above.

Any suggestion as to what I need to do?

Thanks

Your code doesn't close the file.

FileClose() function expects file handle, not file name.

Demos Stogios
224
Demos Stogios  
samjesse:

The process cannot access the file because it is being used by another process.

This is the message I get from Window 10 when I try to open a file by double clicking its name in Windows Explorer after this mql5 code opened and closed the same file.

Since the code needs to run on many charts, it works the first time but failed to open the file the second time due to the the file process issue above.

Any suggestion as to what I need to do?

Thanks

You can also use FILE_SHARE_READ|FILE_READ and you will not have to close the file in any of the charts

greets

To add comments, please log in or register