Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Views:
3736
Rating:
(37)
Published:
2013.03.27 14:46
Updated:
2016.11.22 07:32
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The script searches all text files in the terminal local folder and deletes those of them whose creation data is less than the data value on the "InpFilesDate" input parameter. The terminal local folder location can be obtained calling the TerminalInfoString() function.

PrintFormat("The path to the terminal local folder: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));

Note: The script will delete all text files which were created earlier than January 1st, 2010 from the terminal local folder (the InpFilesDate parameter value is default). Thus, before launching it, make sure that you have no text files with an important information in the terminal local folder.

Code:

//--- show the window of input parameters when launching the script
#property script_show_inputs
//--- date for old files
input datetime InpFilesDate=D'2010.01.01 00:00';
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string   file_name;      // variable for storing file names
   string   filter="*.txt"; // filter for searching the files
   datetime create_date;    // file creation date
   string   files[];        // list of file names
   int      def_size=25;    // array size by default
   int      size=0;         // number of files
//--- allocate memory for the array
   ArrayResize(files,def_size);
//--- receive the search handle in the local folder's root
   long search_handle=FileFindFirst(filter,file_name);
//--- check if FileFindFirst() executed successfully
   if(search_handle!=INVALID_HANDLE)
     {
      //--- searching files in the loop
      do
        {
         files[size]=file_name;
         //--- increase the array size
         size++;
         if(size==def_size)
           {
            def_size+=25;
            ArrayResize(files,def_size);
           }
         //--- reset the error value
         ResetLastError();
         //--- receive the file creation date
         create_date=(datetime)FileGetInteger(file_name,FILE_CREATE_DATE,false);
         //--- check if the file is old
         if(create_date<InpFilesDate)
           {
            PrintFormat("%s file deleted!",file_name);
            //--- delete the old file
            FileDelete(file_name);
           }
        }
      while(FileFindNext(search_handle,file_name));
      //--- close the search handle
      FileFindClose(search_handle);
     }
   else
     {
      Print("Files not found!");
      return;
     }
//--- check what files have remained
   PrintFormat("Results:");
   for(int i=0;i<size;i++)
     {
      if(FileIsExist(files[i]))
         PrintFormat("%s file exists!",files[i]);
      else
         PrintFormat("%s file deleted!",files[i]);
     }
  }

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/1610

Demo_FileCopy Demo_FileCopy

The script demonstrates the example of using the FileCopy() function

Demo_FileFind Demo_FileFind

The script is a simple example of using the FileFindFirst(), FileFindNext() and FileFindClose() functions

The20sv0.20 The20sv0.20

The semaphore trend signal indicator

Demo_FileMove Demo_FileMove

The script demonstrates the example of using the FileMove() function