Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2013.04.10 13:09

Demo_FileSize - script for MetaTrader 5

| English Русский 中文 Español Deutsch 日本語 Português

votes: 24

The script sorts one by one all CSV files in the general folder of all client terminals to obtain their sizes. After getting the size, its value is compared to the "InpThresholdSize" threshold value and according to the result the file is placed either in the "InpBigFolderName", or the "InpSmallFolderName" named folder. Thus large and small dimension files are sorted.

Besides using the FileSize() function, there are also the FileFindFirst(), the FileFindNext() and the FileFindClose() functions used in the script to sort the files and the FileMove() function to move them.


//--- show the window of input parameters when launching the script
#property script_show_inputs
//--- input parameters
input ulong  InpThresholdSize=20;        // file threshold size in kilobytes
input string InpBigFolderName="big";     // folder for large files
input string InpSmallFolderName="small"; // folder for small files
//| Script program start function                                    |
void OnStart()
   string   file_name;      // variable for storing file names
   string   filter="*.csv"; // filter for searching the files
   ulong    file_size=0;    // file size in bytes
   int      size=0;         // number of files
//--- print the path to the file we are going to work with
   PrintFormat("Working in %s\\Files\\ folder",TerminalInfoString(TERMINAL_COMMONDATA_PATH));
//--- receive the search handle in common folder's root of all terminals
   long search_handle=FileFindFirst(filter,file_name,FILE_COMMON);
//--- check if FileFindFirst() has been executed successfully
      //--- move files in the loop according to their size
         //--- open the file
         int file_handle=FileOpen(file_name,FILE_READ|FILE_CSV|FILE_COMMON);
            //--- receive the file size
            //--- close the file
            PrintFormat("Failed to open %s file, Error code = %d",file_name,GetLastError());
         //--- print the file size
         PrintFormat("Size of %s file is equal to %d bytes",file_name,file_size);
         //--- define the path for moving the file
         string path;
         //--- move the file
            PrintFormat("%s file is moved",file_name);
            PrintFormat("Error, code = %d",GetLastError());
      //--- close the search handle
      Print("Files not found!");

Translated from Russian by MetaQuotes Software Corp.
Original code:

Demo_FileReadDouble Demo_FileReadDouble

The indicator demonstrates the example of using the FileReadDouble() function

Demo_FileWriteDouble Demo_FileWriteDouble

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

Demo_FileTell Demo_FileTell

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

Demo_FileWriteInteger Demo_FileWriteInteger

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