Download MetaTrader 5

help:delete the information from txt

To add comments, please log in or register
Share your program via Code Base. Gain access to millions of traders!
ayoublaser
99
ayoublaser 2015.06.24 01:20 

i want to delete the information from txt every tick

how can i do this

Keith Watford
Moderator
9624
Keith Watford 2015.06.24 02:02  
What is txt?
ayoublaser
99
ayoublaser 2015.06.24 10:35  
it's a file
whroeder1
14514
whroeder1 2015.06.24 12:02  
ayoub: it's a file
FileDelete
ayoublaser
99
ayoublaser 2015.06.24 12:40  

it not work ,Does not read the new value it read just last value, can you correct this expert, please.

//--- display the window of input parameters when launching the script
//--- input parameters
input string InpFileName="data.bin";
input string InpDirectoryName="SomeFolder";
//+------------------------------------------------------------------+
//| Structure for storing price data                                 |
//+------------------------------------------------------------------+
struct prices
  {
   datetime          date; // date
   double            bid;  // bid price
   double            ask;  // ask price
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- structure array
   prices arr[];
//--- file path
   string path=InpDirectoryName+"//"+InpFileName;
//--- open the file
   ResetLastError();
   int file_handle=FileOpen(path,FILE_READ|FILE_BIN);
   if(file_handle!=INVALID_HANDLE)
     {
      //--- read all data from the file to the array
      FileReadArray(file_handle,arr);
      //--- receive the array size
      int size=ArraySize(arr);
      //--- print data from the array
      for(int i=0;i<size;i++)
         Print("Date = ",arr[i].date," Bid = ",arr[i].bid," Ask = ",arr[i].ask);
      Print("Total data = ",size);
      //--- close the file

FileDelete(InpFileName);

      FileClose(file_handle);
     }
   else
      Print("File open failed, error ",GetLastError());
  }
whroeder1
14514
whroeder1 2015.06.24 14:02  
ayoub: it not work
  1. It does work. You would have found out why had you bothered to check your return codes. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2.    string path=InpDirectoryName+"//"+InpFileName;
       int file_handle=FileOpen(path,FILE_READ|FILE_BIN);
    
    FileDelete(InpFileName);
    
    Your file name is in path. Why don't you try deleting it?
ayoublaser
99
ayoublaser 2015.06.24 18:58  

i use that but when start delete it can't read again

the "file find first" , "next" and "close" it Necessary to define the new value and "file is exist"



whroeder1
14514
whroeder1 2015.06.24 19:32  
ayoub: i use that but when start delete it can't read again
Make up your mind. If you want to delete the information, you can't read it again.
Demos Stogios
189
Demos Stogios 2015.06.24 20:55  

From what I can undestand, OP actually wants to empty the contents of the file and not to delete the whole file. So, OP, first FileClose(yourfile); and then FileOpen("filename.bin",FILE_WRITE|FILE_BIN);

To be more clear, I repeat, do not FILE_READ at that time and your file will be emptied

 

best regards 

JD4
1101
JD4 2015.06.24 22:26  
I think they want to delete specific information from within the file, not the entire file itself.  FileDelete would not be the correct solution to the problem in this case.
ayoublaser
99
ayoublaser 2015.06.26 00:22  
I want to offload content the txt after reading the information
12
To add comments, please log in or register